From 396376669c19784100e785c9ba9d3930a8a1ccbd Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 23 Sep 2022 15:02:15 -0400 Subject: [PATCH] Add basic login/logout forms. The new forms need better styling. Remove index_cache. --- undercover/routes.py | 22 ++++++++++++---------- undercover/templates/writing.jinja2 | 20 +++++++++++++++++++- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/undercover/routes.py b/undercover/routes.py index e2a2646..7b3713d 100644 --- a/undercover/routes.py +++ b/undercover/routes.py @@ -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']) diff --git a/undercover/templates/writing.jinja2 b/undercover/templates/writing.jinja2 index a07a2b5..342b6eb 100644 --- a/undercover/templates/writing.jinja2 +++ b/undercover/templates/writing.jinja2 @@ -42,7 +42,25 @@

The secret cover letter generator

{% if username %} -

You are logged in as {{ username }}

+
+

You are logged in as {{ username }}

+
+ +
+
+ {% else %} +
+

You are here as a guest.

+
+ + + + + + + +
+
{% endif %} {% from "_formhelpers.jinja2" import render_field %}