IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit 5555952b authored by Emi Simpson's avatar Emi Simpson
Browse files

Don't wipe login forms on error

parent d04fecfa
Pipeline #262 failed with stages
in 36 seconds
......@@ -36,6 +36,9 @@ def post_login() -> str:
signup = False
required_fields = ['username', 'password']
for key, val in request.form.items():
flash(val, f'data-{"signup" if signup else "login"}-{key}')
missing_fields = [field for field in required_fields if field not in request.form]
if len(missing_fields) > 0:
flash(f"Missing Fields: {missing_fields}", "error-generic-generic")
......
......@@ -37,33 +37,80 @@ input {
</style>
{% endblock %}
{% block main %}
{#
A hack to allow extracting information from a loop
See https://jinja.palletsprojects.com/en/3.0.x/templates/#assignments
#}
{% set ns = namespace(
login_user = "",
login_pass = "",
signup_user = "",
signup_pass = "",
signup_frst = "",
signup_last = "",
signup_emal = "",
) %}
{# Look for overrides set by a previous call #}
{% for category, message in get_flashed_messages(with_categories=true) %}
{% if category == "data-login-username" %}
{% set ns.login_user = message %}
{% elif category == "data-login-password" %}
{% set ns.login_pass = message %}
{% elif category == "data-signup-username" %}
{% set ns.signup_user = message %}
{% elif category == "data-signup-password" %}
{% set ns.signup_pass = message %}
{% elif category == "data-signup-name" %}
{% set ns.signup_name = message %}
{% elif category == "data-signup-last_name" %}
{% set ns.signup_last = message %}
{% elif category == "data-signup-email" %}
{% set ns.signup_emal = message %}
{% endif %}
{% endfor %}
<div id=login>
<section>
<form method=POST>
<h2> Create Account </h2>
<div class="input-field">
<label>Username</label>
<input name="username" {{ utils.highlight_if_error("signup", "username") }}>
<input
name="username"
value="{{ns.signup_user}}"
{{ utils.highlight_if_error("signup", "username") }} />
{{ utils.show_field_error("signup", "username") }}
</div>
<div class="input-field">
<label>Password</label>
<input name="password" type=password {{ utils.highlight_if_error("signup", "password") }}>
<input
name="password"
type=password
value="{{ns.signup_pass}}"
{{ utils.highlight_if_error("signup", "password") }} />
{{ utils.show_field_error("signup", "password") }}
<span class="small">The only requirement is that passwords must be at least 16 characters</span>
</div>
<div class="input-field">
<label>First/Display Name</label>
<input name="name" {{ utils.highlight_if_error("signup", "name") }}>
<input
name="name"
value="{{ns.signup_name}}"
{{ utils.highlight_if_error("signup", "name") }} />
{{ utils.show_field_error("signup", "name") }}
</div>
<div class="input-field">
<label>Last Name (Optional)</label>
<input name="last_name">
<input name="last_name" value="{{ns.signup_last}}" />
</div>
<div class="input-field">
<label>Email</label>
<input name="email" type=email {{ utils.highlight_if_error("signup", "email") }}>
<input
name="email"
type=email
value="{{ns.signup_emal}}"
{{ utils.highlight_if_error("signup", "email") }} />
{{ utils.show_field_error("signup", "email") }}
</div>
<div class="button-wrapper">
......@@ -76,12 +123,19 @@ input {
<h2> Login </h2>
<div class="input-field">
<label>Username / Email</label>
<input name="username" {{ utils.highlight_if_error("login", "username") }}>
<input
name="username"
value="{{ns.login_user}}"
{{ utils.highlight_if_error("login", "username") }} />
{{ utils.show_field_error("login", "username") }}
</div>
<div class="input-field">
<label>Password</label>
<input name="password" type=password {{ utils.highlight_if_error("login", "password") }}>
<input
name="password"
type=password
value="{{ns.login_pass}}"
{{ utils.highlight_if_error("login", "password") }} />
{{ utils.show_field_error("login", "password") }}
</div>
<div class="button-wrapper">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment