From 2ee23bb33e7c735415610c2ba3af9ba45870dc51 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sun, 2 Oct 2022 02:27:23 -0400 Subject: [PATCH] Move login/create account into a modal. Some redundancy floating around. Error handling is probably wonky. Modal should have a bit more detail in the future. --- undercover/routes.py | 19 ++---- undercover/static/styles.css | 81 ++++++++++++++++++++++-- undercover/templates/_formhelpers.jinja2 | 43 +++++++++++++ undercover/templates/base.jinja2 | 29 +++++++++ undercover/templates/writing.jinja2 | 26 ++------ 5 files changed, 156 insertions(+), 42 deletions(-) diff --git a/undercover/routes.py b/undercover/routes.py index cb1ac99..65d6299 100644 --- a/undercover/routes.py +++ b/undercover/routes.py @@ -78,10 +78,8 @@ class CLForm(Form): ) def to_cl_data(self) -> CLData: - selected_letter = self.letterName.data or '1' - return CLData( - selectedLetter=int(selected_letter) - 1, + selectedLetter=int(self.letterName.data or '1') - 1, username=self.username.data, company=self.company.data, jobAndPronoun=self.jobAndPronoun.data, @@ -110,6 +108,8 @@ def render_index( @writing_blueprint.route('/login', methods=['POST', 'GET']) def login() -> Response | str: + if request.form.get('confirm-password'): + return create_account() if request.method == 'POST': username = request.form['login'] if db.login(username, request.form['password']): @@ -117,13 +117,7 @@ def login() -> Response | str: return redirect('/') return render_index(error="Invalid username or password", status=401) - return ''' -
-

-

-

-
- ''' + return render_index(status=404) @writing_blueprint.route('/logout', methods=['POST', 'GET']) @@ -191,11 +185,6 @@ def index_get() -> Response: return render_index(form=form) -@writing_blueprint.route('/create_account', methods=['GET']) -def create_account_page() -> str: - return render_template('create_account.jinja2') - - @writing_blueprint.route('/create_account', methods=['POST']) def create_account() -> Response: email_address = request.form['login'] diff --git a/undercover/static/styles.css b/undercover/static/styles.css index 474aedc..682d9cc 100644 --- a/undercover/static/styles.css +++ b/undercover/static/styles.css @@ -124,8 +124,9 @@ div.user { div.user form { display: flex; - flex-direction: column; + flex-direction: row; font-size: 70%; + justify-content: end; } div.user form div { @@ -170,6 +171,8 @@ div.user form input { transition-property: color, background-color; transition-duration: 135ms; transition-timing-function: ease-out; + width: min-content; + white-space: nowrap; } .black-white-button:hover { @@ -187,6 +190,9 @@ div.user form input { .user.logged-in { margin-bottom: 1em; } +.user.logged-out { + font-size: 110%; +} dl { display: flex; @@ -263,8 +269,49 @@ textarea { height: 100%; } +.modal { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + position: absolute; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + scroll-behavior: unset; + background-color: white;/*rgba(0, 0, 0, 0.4);*/ + transition-property: opacity; + transition-duration: 300ms; + transition-timing-function: ease-out; +} + +.modal-background { + background: none; +} + +.modal-content input { + margin-bottom: 2em; +} + +.modal-close-button { + position: absolute; + background: none; + border: none; + font-size: 2rem; + font-weight: bold; + color: #444; + margin: 0.25em; + top: 0; + right: 0; +} + +.modal-close-button:hover { + color: #000; +} + /* Small screens */ -@media only screen and (max-width: 1080px) { +@media only screen and (max-width: 720px) { body { width: 85vw; } @@ -305,7 +352,7 @@ textarea { } /* Big screens */ -@media only screen and (min-width: 1081px) { +@media only screen and (min-width: 721px) { body { min-height: 98%; width: 40vw; @@ -329,9 +376,6 @@ textarea { #closingText { width: 50%; } - div.user form { - flex-direction: row; - } div.user form input { font-size: 110%; padding: 0.5em; @@ -340,9 +384,32 @@ textarea { .login-button { padding: 0; } - .logged-in { + .user { position: absolute; top: 0.5em; right: 1em; } + .modal-background { + background-color: rgba(0, 0, 0, 0.3) + } + .modal-content { + width: 40%; + height: 75%; + position: relative; + border-radius: 3px; + } } + +.transparent { + pointer-events: none; + opacity: 0; +} + +#create-account-form div { + display: flex; + flex-direction: column; +} + +.hidden { + display: none; +} \ No newline at end of file diff --git a/undercover/templates/_formhelpers.jinja2 b/undercover/templates/_formhelpers.jinja2 index 5971558..642d6b2 100644 --- a/undercover/templates/_formhelpers.jinja2 +++ b/undercover/templates/_formhelpers.jinja2 @@ -22,3 +22,46 @@ {{ render_input(field, extra, **kwargs) }} {% endmacro %} + +{% macro modal() %} + +{% endmacro %} diff --git a/undercover/templates/base.jinja2 b/undercover/templates/base.jinja2 index 254a281..67aa312 100644 --- a/undercover/templates/base.jinja2 +++ b/undercover/templates/base.jinja2 @@ -6,10 +6,32 @@ + {% block head %}{{ head }}{% endblock head %} +{{ modal() }} {% if username %}

{{ username }}

@@ -17,6 +39,13 @@
+{% else %} +
+
+
Create account
+
Log in
+
+
{% endif %}

diff --git a/undercover/templates/writing.jinja2 b/undercover/templates/writing.jinja2 index a2d94a5..2adb0d3 100644 --- a/undercover/templates/writing.jinja2 +++ b/undercover/templates/writing.jinja2 @@ -1,5 +1,5 @@ {% extends "base.jinja2" %} -{% from "_formhelpers.jinja2" import render_field, render_label, render_input %} +{% from "_formhelpers.jinja2" import render_field, render_label, render_input, modal %} {% block title %}UnderCover{% endblock %} @@ -38,24 +38,6 @@ {% endblock head %} {% block content %} - {% if not username %} -
-

You are working as a Guest.

-
-
- - -
- -
- - - -
-
-
- {% endif %} -
{% if username %} @@ -67,7 +49,11 @@ onchange="window.location = '/?letter_name=' + this.options[this.value - 1].label" ) }} - + + + {% endif %}