Skip to content

Commit

Permalink
Uniformity in Templates (pallets-eco#743)
Browse files Browse the repository at this point in the history
* Update Russian translations

* Forms method value to lowercase: GET->get, POST->post

* Uniformity of indentation and line breaks in templates

* Fix issues with Flask-SQLAlchemy 2.0 - alas, sqlalchemy-utils hasn't caught up yet - so we can't test with it. (pallets-eco#744)

* Forms method value to lowercase: GET->get, POST->post

* Uniformity of indentation and line breaks in templates

* Add djlint to requirements/tests

* Add base config to djlint

* Adjusted templates based on djlint rules

---------

Co-authored-by: Chris Wagner <[email protected]>
  • Loading branch information
ademaro and jwag956 authored Jan 31, 2023
1 parent 6a2cbf9 commit 7223a6a
Show file tree
Hide file tree
Showing 35 changed files with 500 additions and 524 deletions.
11 changes: 11 additions & 0 deletions .djlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ignore": "H017,H025,H030,H031",
"extension": "html",
"indent": "2",
"profile": "jinja",
"format_attribute_template_tags": "true",
"max_line_length": 120,
"max_attribute_length": 240,
"blank_line_after_tag": "from,endmacro",
"blank_line_before_tag": "block,extends"
}
16 changes: 5 additions & 11 deletions flask_security/templates/security/_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
{{ field.label }} {{ field(**kwargs)|safe }}
{% if field.errors %}
<ul>
{% for error in field.errors %}
<li class="fs-error-msg">{{ error }}</li>
{% endfor %}
{% for error in field.errors %}<li class="fs-error-msg">{{ error }}</li>{% endfor %}
</ul>
{% endif %}
</div>
Expand All @@ -19,9 +17,7 @@
<div class="fs-div" id="{{ field.id if field else 'fs-field' }}">
{% if field and field.errors %}
<ul>
{% for error in field.errors %}
<li class="fs-error-msg">{{ error }}</li>
{% endfor %}
{% for error in field.errors %}<li class="fs-error-msg">{{ error }}</li>{% endfor %}
</ul>
{% endif %}
</div>
Expand All @@ -31,11 +27,9 @@
{% macro render_form_errors(form) %}
{% if form.form_errors %}
<div class="fs-div" id="fs-form-errors">
<ul>
{% for error in form.form_errors %}
<li class="fs-error-msg">{{ error }}</li>
{% endfor %}
</ul>
<ul>
{% for error in form.form_errors %}<li class="fs-error-msg">{{ error }}</li>{% endfor %}
</ul>
</div>
{% endif %}
{% endmacro %}
Expand Down
92 changes: 56 additions & 36 deletions flask_security/templates/security/_menu.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
{% if security.registerable or security.recoverable or security.confirmable or security.unified_signin or security.two_factor or security.webauthn %}
<hr>
<h2>{{ _fsdomain('Menu') }}</h2>
<ul>
{% if current_user and current_user.is_authenticated %}
{# already authenticated user #}
<li><a href="{{ url_for_security('logout') }}">{{ _fsdomain("Sign out") }}</a></li>
{% if security.changeable %}
<li><a href="{{ url_for_security('change_password') }}">{{ _fsdomain("Change Password") }}</li>
{% endif %}
{% if security.two_factor %}
<li><a href="{{ url_for_security('two_factor_setup') }}">{{ _fsdomain("Two Factor Setup") }}</li>
{% endif %}
{% if security.unified_signin %}
<li><a href="{{ url_for_security('us_setup') }}">{{ _fsdomain("Unified Signin Setup") }}</li>
{% endif %}
{% if security.webauthn %}
<li><a href="{{ url_for_security('wan_register') }}">{{ _fsdomain("WebAuthn Setup") }}</li>
{% endif %}
{% else %}
{% if not skip_login_menu %}
<li><a href="{{ url_for_security('login') }}{% if 'next' in request.args %}?next={{ request.args.next|urlencode }}{% endif %}">{{ _fsdomain('Login') }}</a></li>
{% endif %}
{% if security.unified_signin and not skip_login_menu %}
<li><a href="{{ url_for_security('us_signin') }}{% if 'next' in request.args %}?next={{ request.args.next|urlencode }}{% endif %}">{{ _fsdomain("Unified Sign In") }}</a><br/></li>
{% endif %}
{% if security.registerable %}
<li><a href="{{ url_for_security('register') }}{% if 'next' in request.args %}?next={{ request.args.next|urlencode }}{% endif %}">{{ _fsdomain('Register') }}</a><br/></li>
{% endif %}
{% if security.recoverable %}
<li><a href="{{ url_for_security('forgot_password') }}">{{ _fsdomain('Forgot password') }}</a><br/></li>
{% endif %}
{% if security.confirmable %}
<li><a href="{{ url_for_security('send_confirmation') }}">{{ _fsdomain('Confirm account') }}</a></li>
{% endif %}
{% endif %}
</ul>
<hr>
<h2>{{ _fsdomain('Menu') }}</h2>
<ul>
{% if current_user and current_user.is_authenticated %}
{# already authenticated user #}
<li>
<a href="{{ url_for_security('logout') }}">{{ _fsdomain("Sign out") }}</a>
</li>
{% if security.changeable %}
<li>
<a href="{{ url_for_security('change_password') }}">{{ _fsdomain("Change Password") }}
</li>
{% endif %}
{% if security.two_factor %}
<li>
<a href="{{ url_for_security('two_factor_setup') }}">{{ _fsdomain("Two Factor Setup") }}
</li>
{% endif %}
{% if security.unified_signin %}
<li>
<a href="{{ url_for_security('us_setup') }}">{{ _fsdomain("Unified Signin Setup") }}
</li>
{% endif %}
{% if security.webauthn %}
<li>
<a href="{{ url_for_security('wan_register') }}">{{ _fsdomain("WebAuthn Setup") }}
</li>
{% endif %}
{% else %}
{% if not skip_login_menu %}
<li>
<a href="{{ url_for_security('login') }}{%- if 'next' in request.args -%}?next={{ request.args.next|urlencode }}{%- endif -%}">{{ _fsdomain('Login') }}</a>
</li>
{% endif %}
{% if security.unified_signin and not skip_login_menu %}
<li>
<a href="{{ url_for_security('us_signin') }}{%- if 'next' in request.args -%}?next={{ request.args.next|urlencode }}{%- endif -%}">{{ _fsdomain('Unified Sign In') }}</a>
</li>
{% endif %}
{% if security.registerable %}
<li>
<a href="{{ url_for_security('register') }}{%- if 'next' in request.args -%}?next={{ request.args.next|urlencode }}{%- endif -%}">{{ _fsdomain('Register') }}</a>
</li>
{% endif %}
{% if security.recoverable %}
<li>
<a href="{{ url_for_security('forgot_password') }}">{{ _fsdomain('Forgot password') }}</a>
</li>
{% endif %}
{% if security.confirmable %}
<li>
<a href="{{ url_for_security('send_confirmation') }}">{{ _fsdomain('Confirm account') }}</a>
</li>
{% endif %}
{% endif %}
</ul>
{% endif %}
4 changes: 1 addition & 3 deletions flask_security/templates/security/_messages.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{%- with messages = get_flashed_messages(with_categories=true) -%}
{% if messages %}
<ul class="flashes">
{% for category, message in messages %}
<li class="{{ category }} fs-error-msg">{{ message }}</li>
{% endfor %}
{% for category, message in messages %}<li class="{{ category }} fs-error-msg">{{ message }}</li>{% endfor %}
</ul>
{% endif %}
{%- endwith %}
2 changes: 1 addition & 1 deletion flask_security/templates/security/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>{% block title %}{{ title|default }}{% endblock title %}</title>

{%- block metas %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{%- endblock metas %}

{%- block head_scripts %}
Expand Down
28 changes: 14 additions & 14 deletions flask_security/templates/security/change_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
{% from "security/_macros.html" import render_field_with_errors, render_field %}

{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain('Change password') }}</h1>
<form action="{{ url_for_security('change_password') }}" method="POST" name="change_password_form">
{{ change_password_form.hidden_tag() }}
{% if active_password %}
{{ render_field_with_errors(change_password_form.password) }}
{% else %}
<h3>{{ _fsdomain('You do not currently have a password - this will add one.') }}</h3>
{% endif %}
{{ render_field_with_errors(change_password_form.new_password) }}
{{ render_field_with_errors(change_password_form.new_password_confirm) }}
{{ render_field(change_password_form.submit) }}
</form>
{% endblock %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain('Change password') }}</h1>
<form action="{{ url_for_security('change_password') }}" method="post" name="change_password_form">
{{ change_password_form.hidden_tag() }}
{% if active_password %}
{{ render_field_with_errors(change_password_form.password) }}
{% else %}
<h3>{{ _fsdomain('You do not currently have a password - this will add one.') }}</h3>
{% endif %}
{{ render_field_with_errors(change_password_form.new_password) }}
{{ render_field_with_errors(change_password_form.new_password_confirm) }}
{{ render_field(change_password_form.submit) }}
</form>
{% endblock content %}
4 changes: 3 additions & 1 deletion flask_security/templates/security/email/change_notice.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<p>{{ _fsdomain('Your password has been changed.') }}</p>
{% if security.recoverable %}
<p>{{ _fsdomain('If you did not change your password,') }} <a href="{{ url_for_security('forgot_password', _external=True) }}">{{ _fsdomain('click here to reset it') }}</a>.</p>
<p>
{{ _fsdomain('If you did not change your password,') }} <a href="{{ url_for_security('forgot_password', _external=True) }}">{{ _fsdomain('click here to reset it') }}</a>.
</p>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
security - the Flask-Security configuration
#}
<p>{{ _fsdomain('Please confirm your email through the link below:') }}</p>

<p><a href="{{ confirmation_link }}">{{ _fsdomain('Confirm my account') }}</a></p>
<p>
<a href="{{ confirmation_link }}">{{ _fsdomain('Confirm my account') }}</a>
</p>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>{{ _fsdomain('Welcome %(email)s!', email=user.email) }}</p>

<p>{{ _fsdomain('You can log into your account through the link below:') }}</p>

<p><a href="{{ login_link }}">{{ _fsdomain('Login now') }}</a></p>
<p>
<a href="{{ login_link }}">{{ _fsdomain('Login now') }}</a>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
user - the entire user model object
security - the Flask-Security configuration
#}
<p><a href="{{ reset_link }}">{{ _fsdomain('Click here to reset your password') }}</a></p>
<p>
<a href="{{ reset_link }}">{{ _fsdomain('Click here to reset your password') }}</a>
</p>
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<p>{{ _fsdomain("Welcome") }} {{ username }}!</p>

<p>{{ _fsdomain("You can log into your account using the following code:") }} {{ token }}</p>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p> {{ user.email }} {{ _fsdomain("can not access mail account") }}</p>
<p>{{ user.email }} {{ _fsdomain("can not access mail account") }}</p>
9 changes: 4 additions & 5 deletions flask_security/templates/security/email/us_instructions.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
security - the Flask-Security configuration
#}
<p>{{ _fsdomain("Welcome") }} {{ username }}!</p>

<p>{{ _fsdomain("You can sign into your account using the following code:") }} {{ token }}</p>

{% if login_link %}
<p>{{ _fsdomain("Or use the link below:") }}</p>

<p><a href="{{ login_link }}">{{ _fsdomain("Sign In") }}</a></p>
{% endif %}
<p>
<a href="{{ login_link }}">{{ _fsdomain("Sign In") }}</a>
</p>
{% endif %}
8 changes: 4 additions & 4 deletions flask_security/templates/security/email/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
security - the Flask-Security configuration
#}
<p>{{ _fsdomain('Welcome %(email)s!', email=user.email) }}</p>

{% if security.confirmable %}
<p>{{ _fsdomain('You can confirm your email through the link below:') }}</p>

<p><a href="{{ confirmation_link }}">{{ _fsdomain('Confirm my account') }}</a></p>
<p>{{ _fsdomain('You can confirm your email through the link below:') }}</p>
<p>
<a href="{{ confirmation_link }}">{{ _fsdomain('Confirm my account') }}</a>
</p>
{% endif %}
12 changes: 6 additions & 6 deletions flask_security/templates/security/email/welcome_existing.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
enumeration.
#}
<div>{{ _fsdomain('Hello %(email)s!', email=user.email) }}</div>

<div>{{ _fsdomain('Someone (you?) tried to register this email - which is already in our system.') }}</div>

{% if user.username %}
<div>{{ _fsdomain('This account also has the following username associated with it: %(username)s.', username=user.username) }}</div>
<div>
{{ _fsdomain('This account also has the following username associated with it: %(username)s.', username=user.username) }}
</div>
{% endif %}

{% if recovery_link %}
<div>{{ _fsdomain('If you forgot your password you can reset it') }}
<a href="{{ recovery_link }}">{{ _fsdomain(' here.') }}</a>
<div>
{{ _fsdomain('If you forgot your password you can reset it') }}
<a href="{{ recovery_link }}">{{ _fsdomain(' here.') }}</a>
</div>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
for username enumeration.
#}
<div>{{ _fsdomain('Hello %(email)s!', email=email) }}</div>

<div>{{ _fsdomain('You attempted to register with a username "%(username)s" that is already associated with another account.',
username=username) }}</div>

<div>
{{ _fsdomain('You attempted to register with a username "%(username)s" that is already associated with another account.', username=username) }}
</div>
<div>{{ _fsdomain('Please restart the registration process with a different username.') }}</div>
18 changes: 9 additions & 9 deletions flask_security/templates/security/forgot_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{% from "security/_macros.html" import render_field_with_errors, render_field %}

{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain('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 %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain('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 content %}
31 changes: 12 additions & 19 deletions flask_security/templates/security/login_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors, render_form_errors, prop_next %}

{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain('Login') }}</h1>
<form action="{{ url_for_security('login') }}{{ prop_next() }}" method="POST" name="login_user_form">
{% include "security/_messages.html" %}
<h1>{{ _fsdomain('Login') }}</h1>
<form action="{{ url_for_security('login') }}{{ prop_next() }}" method="post" name="login_user_form">
{{ login_user_form.hidden_tag() }}
{{ render_form_errors(login_user_form) }}
{% if "email" in identity_attributes %}
{{ render_field_with_errors(login_user_form.email) }}
{% endif %}
{% if "email" in identity_attributes %}{{ render_field_with_errors(login_user_form.email) }}{% endif %}
{% if login_user_form.username and "username" in identity_attributes %}
{% if "email" in identity_attributes %}
<h3>{{ _fsdomain("or") }}</h3>
{% endif %}
{% if "email" in identity_attributes %}<h3>{{ _fsdomain("or") }}</h3>{% endif %}
{{ render_field_with_errors(login_user_form.username) }}
{% endif %}
<div class="fs-gap">
{{ render_field_with_errors(login_user_form.password) }}</div>
<div class="fs-gap">{{ render_field_with_errors(login_user_form.password) }}</div>
{{ render_field_with_errors(login_user_form.remember) }}
{{ render_field_errors(login_user_form.csrf_token) }}
{{ render_field(login_user_form.submit) }}
Expand All @@ -26,9 +21,8 @@ <h3>{{ _fsdomain("or") }}</h3>
<hr class="fs-gap">
<h2>{{ _fsdomain("Use WebAuthn to Sign In") }}</h2>
<div>
<form method="GET" id="wan-signin-form" name="wan_signin_form">
<input id="wan_signin" name="wan_signin" type="submit" value="{{ _fsdomain('Sign in with WebAuthn') }}"
formaction="{{ url_for_security('wan_signin') }}{{ prop_next() }}">
<form method="get" id="wan-signin-form" name="wan_signin_form">
<input id="wan_signin" name="wan_signin" type="submit" value="{{ _fsdomain('Sign in with WebAuthn') }}" formaction="{{ url_for_security('wan_signin') }}{{ prop_next() }}">
</form>
</div>
{% endif %}
Expand All @@ -37,12 +31,11 @@ <h2>{{ _fsdomain("Use WebAuthn to Sign In") }}</h2>
<h2>{{ _fsdomain("Use Social Oauth to Sign In") }}</h2>
{% for provider in security.oauthglue.provider_names %}
<div class="fs-gap">
<form method="POST" id={{ provider }}-form name={{ provider }}_form>
<input id={{ provider }} name={{ provider }} type="submit" value="{{ _fsdomain('Sign in with ')~provider }}"
formaction="{{ url_for_security('oauthstart', name=provider) }}{{ prop_next() }}">
<form method="post" id="{{ provider }}"-form name="{{ provider }}"_form>
<input id="{{ provider }}" name="{{ provider }}" type="submit" value="{{ _fsdomain('Sign in with ')~provider }}" formaction="{{ url_for_security('oauthstart', name=provider) }}{{ prop_next() }}">
</form>
</div>
{% endfor %}
{% endif %}
{% include "security/_menu.html" %}
{% endblock %}
{% include "security/_menu.html" %}
{% endblock content %}
Loading

0 comments on commit 7223a6a

Please sign in to comment.