Add basic login/logout forms.
The new forms need better styling. Remove index_cache.
This commit is contained in:
parent
00472d39a3
commit
396376669c
|
@ -11,7 +11,6 @@ from wtforms import Form, StringField, TextAreaField, validators
|
||||||
import undercover.db as db
|
import undercover.db as db
|
||||||
from undercover.pdf_builder import CLData
|
from undercover.pdf_builder import CLData
|
||||||
|
|
||||||
index_cache = None
|
|
||||||
writing_blueprint = Blueprint('writing', __name__,)
|
writing_blueprint = Blueprint('writing', __name__,)
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ class CLForm(Form):
|
||||||
|
|
||||||
|
|
||||||
@writing_blueprint.route('/login', methods=['POST', 'GET'])
|
@writing_blueprint.route('/login', methods=['POST', 'GET'])
|
||||||
def login_post():
|
def login():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
if db.login(username, request.form['password']):
|
if db.login(username, request.form['password']):
|
||||||
|
@ -81,16 +80,19 @@ def login_post():
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
@writing_blueprint.route('/logout', methods=['POST'])
|
||||||
|
def logout():
|
||||||
|
session.pop('username', None)
|
||||||
|
return redirect('/')
|
||||||
|
|
||||||
|
|
||||||
@writing_blueprint.route('/', methods=['GET'])
|
@writing_blueprint.route('/', methods=['GET'])
|
||||||
def index_get():
|
def index_get():
|
||||||
global index_cache
|
return render_template(
|
||||||
if not index_cache or 'username' in session:
|
|
||||||
index_cache = render_template(
|
|
||||||
'writing.jinja2',
|
'writing.jinja2',
|
||||||
form=CLForm(),
|
form=CLForm(),
|
||||||
username=session['username']
|
username=session['username']
|
||||||
)
|
)
|
||||||
return index_cache
|
|
||||||
|
|
||||||
|
|
||||||
@writing_blueprint.route('/dbtest', methods=['GET'])
|
@writing_blueprint.route('/dbtest', methods=['GET'])
|
||||||
|
|
|
@ -42,7 +42,25 @@
|
||||||
</a>
|
</a>
|
||||||
<h2>The secret cover letter generator</h2>
|
<h2>The secret cover letter generator</h2>
|
||||||
{% if username %}
|
{% if username %}
|
||||||
<h3>You are logged in as {{ username }}</h3>
|
<div class="user logged-in">
|
||||||
|
<p>You are logged in as {{ username }}</p>
|
||||||
|
<form action="/logout">
|
||||||
|
<input type="submit" value="Logout">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="user logged-out">
|
||||||
|
<p>You are here as a guest.</p>
|
||||||
|
<form action="/login">
|
||||||
|
<label for="username">Username: </label>
|
||||||
|
<input id="username" maxlength="32" minlength="4" name="username" type="text" placeholder="sagev9000">
|
||||||
|
|
||||||
|
<label for="password">Password: </label>
|
||||||
|
<input id="password" maxlength="32" minlength="4" name="password" type="password">
|
||||||
|
|
||||||
|
<input type="submit" value="Logout">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% from "_formhelpers.jinja2" import render_field %}
|
{% from "_formhelpers.jinja2" import render_field %}
|
||||||
|
|
Loading…
Reference in New Issue