Add basic login/logout forms.

The new forms need better styling.
Remove index_cache.
This commit is contained in:
Sage Vaillancourt 2022-09-23 15:02:15 -04:00
parent 00472d39a3
commit 396376669c
2 changed files with 31 additions and 11 deletions

View File

@ -11,7 +11,6 @@ from wtforms import Form, StringField, TextAreaField, validators
import undercover.db as db
from undercover.pdf_builder import CLData
index_cache = None
writing_blueprint = Blueprint('writing', __name__,)
@ -64,7 +63,7 @@ class CLForm(Form):
@writing_blueprint.route('/login', methods=['POST', 'GET'])
def login_post():
def login():
if request.method == 'POST':
username = request.form['username']
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'])
def index_get():
global index_cache
if not index_cache or 'username' in session:
index_cache = render_template(
'writing.jinja2',
form=CLForm(),
username=session['username']
)
return index_cache
return render_template(
'writing.jinja2',
form=CLForm(),
username=session['username']
)
@writing_blueprint.route('/dbtest', methods=['GET'])

View File

@ -42,7 +42,25 @@
</a>
<h2>The secret cover letter generator</h2>
{% 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 %}
{% from "_formhelpers.jinja2" import render_field %}