This commit is contained in:
Daniel Grams 2020-06-07 15:00:09 +02:00
parent 47dc327ea4
commit 818a4291f9
17 changed files with 82 additions and 43 deletions

28
templates/_macros.html Normal file
View File

@ -0,0 +1,28 @@
{% macro render_field_with_errors(field) %}
<p>
{{ field.label }} {{ field(**kwargs)|safe }}
{% if field.errors %}
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</p>
{% endmacro %}
{% macro render_field(field) %}
<p>{{ field(**kwargs)|safe }}</p>
{% endmacro %}
{% macro render_field_errors(field) %}
<p>
{% if field and field.errors %}
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</p>
{% endmacro %}

9
templates/_messages.html Normal file
View File

@ -0,0 +1,9 @@
{%- with messages = get_flashed_messages(with_categories=true) -%}
{% if messages %}
<ul class="flashes">
{% for category, message in messages %}
<li class="{{ category }}">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{%- endwith %}

View File

@ -45,7 +45,6 @@
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link" href="{{ url_for('home') }}">Home</a>
{% if current_user.is_authenticated %}
<li class="nav-item dropdown">
@ -61,8 +60,8 @@
</li>
{% else %}
<a class="nav-item nav-link" href="{{ url_for('security.login') }}">Login</a>
<a class="nav-item nav-link" href="{{ url_for('security.register') }}">Register</a>
<a class="nav-item nav-link" href="{{ url_for('security.login') }}">Anmelden</a>
<a class="nav-item nav-link" href="{{ url_for('security.register') }}">Registrieren</a>
{% endif %}
</div>
@ -71,6 +70,9 @@
{%- endblock navbar %}
<div class="body-content">
{% include "_messages.html" %}
{% block content -%}
{%- endblock content %}
</div>

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Change password') }}</h1>
<form action="{{ url_for_security('change_password') }}" method="POST" name="change_password_form">
{{ change_password_form.hidden_tag() }}

View File

@ -1,13 +1,13 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Send password reset instructions') }}</h1>
<form action="{{ url_for_security('forgot_password') }}" method="POST" name="forgot_password_form">
{{ forgot_password_form.hidden_tag() }}
{{ render_field_with_errors(forgot_password_form.email) }}
{{ render_field(forgot_password_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,9 +1,9 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% from "_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Login') }}</h1>
<h1>Anmelden</h1>
<form action="{{ url_for_security('login') }}" method="POST" name="login_user_form">
{{ login_user_form.hidden_tag() }}
{{ render_field_with_errors(login_user_form.email) }}
@ -12,5 +12,5 @@
{{ render_field_errors(login_user_form.csrf_token) }}
{{ render_field(login_user_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,9 +1,9 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Register') }}</h1>
<h1>Registrieren</h1>
<form action="{{ url_for_security('register') }}" method="POST" name="register_user_form">
{{ register_user_form.hidden_tag() }}
{{ render_field_with_errors(register_user_form.email) }}
@ -13,5 +13,5 @@
{% endif %}
{{ render_field(register_user_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Reset password') }}</h1>
<form action="{{ url_for_security('reset_password', token=reset_password_token) }}" method="POST" name="reset_password_form">
{{ reset_password_form.hidden_tag() }}
@ -10,5 +10,5 @@
{{ render_field_with_errors(reset_password_form.password_confirm) }}
{{ render_field(reset_password_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,13 +1,13 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Resend confirmation instructions') }}</h1>
<form action="{{ url_for_security('send_confirmation') }}" method="POST" name="send_confirmation_form">
{{ send_confirmation_form.hidden_tag() }}
{{ render_field_with_errors(send_confirmation_form.email) }}
{{ render_field(send_confirmation_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,13 +1,13 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _('Login') }}</h1>
<form action="{{ url_for_security('login') }}" method="POST" name="send_login_form">
{{ send_login_form.hidden_tag() }}
{{ render_field_with_errors(send_login_form.email) }}
{{ render_field(send_login_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_no_label, render_field_errors %}
{% from "_macros.html" import render_field_with_errors, render_field, render_field_no_label, render_field_errors %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Two-factor authentication adds an extra layer of security to your account") }}</h1>
<h2>{{ _("In addition to your username and password, you'll need to use a code that we will send you") }}</h2>
<form action="{{ url_for_security("two_factor_setup") }}" method="POST" name="two_factor_setup_form">
@ -34,5 +34,5 @@
{{ render_field_with_errors(two_factor_verify_code_form.code) }}
{{ render_field(two_factor_verify_code_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Two-factor Authentication") }}</h1>
<h2>{{ _("Please enter your authentication code") }}</h2>
<form action="{{ url_for_security("two_factor_token_validation") }}" method="POST"
@ -22,5 +22,5 @@
{% endif %}
{{ render_field(two_factor_rescue_form.submit) }}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Please Enter Your Password") }}</h1>
<form action="{{ url_for_security("two_factor_verify_password") }}" method="POST"
name="two_factor_verify_password_form">

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% from "_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Setup Unified Sign In options") }}</h1>
<form action="{{ url_for_security("us_setup") }}" method="POST"
name="us_setup_form">

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% from "_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Sign In") }}</h1>
<form action="{{ url_for_security("us_signin") }}" method="POST"
name="us_signin_form">
@ -25,5 +25,5 @@
{{ render_field(us_signin_form.submit_send_code, formaction=url_for_security('us_signin_send_code')) }}
{% endif %}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% from "_macros.html" import render_field_with_errors, render_field, render_field_errors %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Please re-authenticate") }}</h1>
<form action="{{ url_for_security("us_verify") }}{% if 'next' in request.args %}?next={{ request.args.next|urlencode }}{% endif %}" method="POST"
name="us_verify_form">
@ -23,5 +23,5 @@
{{ render_field(us_verify_form.submit_send_code, formaction=send_code_to) }}
{% endif %}
</form>
{% include "security/_menu.html" %}
{% endblock %}

View File

@ -1,8 +1,8 @@
{% extends "layout.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field %}
{% from "_macros.html" import render_field_with_errors, render_field %}
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _("Please Enter Your Password") }}</h1>
<form action="{{ url_for_security("verify") }}{% if 'next' in request.args %}?next={{ request.args.next|urlencode }}{% endif %}" method="POST"
name="verify_form">