refactor: template overhaul

This commit is contained in:
Éloi Rivard 2023-08-14 15:28:20 +02:00
parent d27aab8651
commit 324b36c829
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
58 changed files with 95 additions and 48 deletions

View file

@ -43,7 +43,7 @@ def mail_index(user):
else:
flash(_("The test invitation mail has not been sent correctly"), "error")
return render_template("mail/admin.html", form=form, menuitem="admin")
return render_template("mails/admin.html", form=form, menuitem="admin")
@bp.route("/mail/test.html")
@ -51,7 +51,7 @@ def mail_index(user):
def test_html(user):
base_url = url_for("core.account.index", _external=True)
return render_template(
"mail/test.html",
"mails/test.html",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
logo=current_app.config.get("LOGO"),
@ -66,7 +66,7 @@ def test_html(user):
def test_txt(user):
base_url = url_for("core.account.index", _external=True)
return render_template(
"mail/test.txt",
"mails/test.txt",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=current_app.config.get("SERVER_NAME", base_url),
)
@ -87,7 +87,7 @@ def password_init_html(user):
)
return render_template(
"mail/firstlogin.html",
"mails/firstlogin.html",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
reset_url=reset_url,
@ -110,7 +110,7 @@ def password_init_txt(user):
)
return render_template(
"mail/firstlogin.txt",
"mails/firstlogin.txt",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=current_app.config.get("SERVER_NAME", base_url),
reset_url=reset_url,
@ -132,7 +132,7 @@ def password_reset_html(user):
)
return render_template(
"mail/reset.html",
"mails/reset.html",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
reset_url=reset_url,
@ -155,7 +155,7 @@ def password_reset_txt(user):
)
return render_template(
"mail/reset.txt",
"mails/reset.txt",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=current_app.config.get("SERVER_NAME", base_url),
reset_url=reset_url,
@ -174,7 +174,7 @@ def invitation_html(user, identifier, email):
)
return render_template(
"mail/invitation.html",
"mails/invitation.html",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
registration_url=registration_url,
@ -197,7 +197,7 @@ def invitation_txt(user, identifier, email):
)
return render_template(
"mail/invitation.txt",
"mails/invitation.txt",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
registration_url=registration_url,
@ -216,7 +216,7 @@ def email_confirmation_html(user, identifier, email):
)
return render_template(
"mail/email-confirmation.html",
"mails/email-confirmation.html",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
confirmation_url=email_confirmation_url,
@ -239,7 +239,7 @@ def email_confirmation_txt(user, identifier, email):
)
return render_template(
"mail/email-confirmation.txt",
"mails/email-confirmation.txt",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
confirmation_url=email_confirmation_url,

View file

@ -4,7 +4,7 @@ from . import account
from . import admin
from . import groups
bp = Blueprint("core", __name__)
bp = Blueprint("core", __name__, template_folder="templates")
bp.register_blueprint(account.bp)
bp.register_blueprint(admin.bp)

View file

@ -15,12 +15,12 @@ def send_test_mail(email):
website_name=current_app.config.get("NAME", "Canaille")
)
text_body = render_template(
"mail/test.txt",
"mails/test.txt",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
)
html_body = render_template(
"mail/test.html",
"mails/test.html",
site_name=current_app.config.get("NAME", "Canaille"),
site_url=base_url,
logo=f"cid:{logo_cid[1:-1]}" if logo_cid else None,
@ -54,13 +54,13 @@ def send_password_reset_mail(user, mail):
website_name=current_app.config.get("NAME", base_url)
)
text_body = render_template(
"mail/reset.txt",
"mails/reset.txt",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
reset_url=reset_url,
)
html_body = render_template(
"mail/reset.html",
"mails/reset.html",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
reset_url=reset_url,
@ -95,13 +95,13 @@ def send_password_initialization_mail(user, email):
website_name=current_app.config.get("NAME", base_url)
)
text_body = render_template(
"mail/firstlogin.txt",
"mails/firstlogin.txt",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
reset_url=reset_url,
)
html_body = render_template(
"mail/firstlogin.html",
"mails/firstlogin.html",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
reset_url=reset_url,
@ -126,13 +126,13 @@ def send_invitation_mail(email, registration_url):
website_name=current_app.config.get("NAME", base_url)
)
text_body = render_template(
"mail/invitation.txt",
"mails/invitation.txt",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
registration_url=registration_url,
)
html_body = render_template(
"mail/invitation.html",
"mails/invitation.html",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
registration_url=registration_url,
@ -157,13 +157,13 @@ def send_confirmation_email(email, confirmation_url):
website_name=current_app.config.get("NAME", base_url)
)
text_body = render_template(
"mail/email-confirmation.txt",
"mails/email-confirmation.txt",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
confirmation_url=confirmation_url,
)
html_body = render_template(
"mail/email-confirmation.html",
"mails/email-confirmation.html",
site_name=current_app.config.get("NAME", base_url),
site_url=base_url,
confirmation_url=confirmation_url,

View file

@ -19,7 +19,7 @@ def index(user):
abort(404)
return render_htmx_template(
"oidc/admin/authorization_list.html",
"authorization_list.html",
menuitem="admin",
table_form=table_form,
)
@ -29,7 +29,7 @@ def index(user):
@permissions_needed("manage_oidc")
def view(user, authorization):
return render_template(
"oidc/admin/authorization_view.html",
"authorization_view.html",
authorization=authorization,
menuitem="admin",
)

View file

@ -7,7 +7,7 @@ from . import endpoints
from . import tokens
from . import well_known
bp = Blueprint("oidc", __name__)
bp = Blueprint("oidc", __name__, template_folder="templates")
bp.register_blueprint(authorizations.bp)
bp.register_blueprint(clients.bp)

View file

@ -27,7 +27,7 @@ def index(user):
abort(404)
return render_htmx_template(
"oidc/admin/client_list.html", menuitem="admin", table_form=table_form
"client_list.html", menuitem="admin", table_form=table_form
)
@ -37,18 +37,14 @@ def add(user):
form = ClientAddForm(request.form or None)
if not request.form or form.form_control():
return render_template(
"oidc/admin/client_add.html", form=form, menuitem="admin"
)
return render_template("client_add.html", form=form, menuitem="admin")
if not form.validate():
flash(
_("The client has not been added. Please check your information."),
"error",
)
return render_template(
"oidc/admin/client_add.html", form=form, menuitem="admin"
)
return render_template("client_add.html", form=form, menuitem="admin")
client_id = gen_salt(24)
client_id_issued_at = datetime.datetime.now(datetime.timezone.utc)
@ -106,7 +102,7 @@ def client_edit(client):
if not request.form or form.form_control():
return render_template(
"oidc/admin/client_edit.html", form=form, client=client, menuitem="admin"
"client_edit.html", form=form, client=client, menuitem="admin"
)
if not form.validate():
@ -115,7 +111,7 @@ def client_edit(client):
"error",
)
return render_template(
"oidc/admin/client_edit.html", form=form, client=client, menuitem="admin"
"client_edit.html", form=form, client=client, menuitem="admin"
)
client.update(

View file

@ -30,7 +30,7 @@ def consents(user):
)
return render_template(
"oidc/user/consent_list.html",
"consent_list.html",
consents=consents,
menuitem="consents",
scope_details=SCOPE_DETAILS,
@ -55,7 +55,7 @@ def pre_consents(user):
nb_preconsents = len(preconsented)
return render_template(
"oidc/user/preconsent_list.html",
"preconsent_list.html",
menuitem="consents",
scope_details=SCOPE_DETAILS,
ignored_scopes=["openid"],

View file

@ -121,7 +121,7 @@ def authorize():
form = AuthorizeForm(request.form or None)
return render_template(
"oidc/user/authorize.html",
"authorize.html",
user=user,
grant=grant,
client=client,
@ -283,9 +283,7 @@ def end_session():
or (data.get("logout_hint") and data["logout_hint"] != user.user_name[0])
) and not session.get("end_session_confirmation"):
session["end_session_data"] = data
return render_template(
"oidc/user/logout.html", form=form, client=client, menu=False
)
return render_template("logout.html", form=form, client=client, menu=False)
if data.get("id_token_hint"):
id_token = jwt.decode(
@ -326,9 +324,7 @@ def end_session():
"end_session_confirmation"
):
session["end_session_data"] = data
return render_template(
"oidc/user/logout.html", form=form, client=client, menu=False
)
return render_template("logout.html", form=form, client=client, menu=False)
user.logout()

View file

@ -40,5 +40,5 @@
{{ table.search(table_form, "table.codes") }}
</div>
{% include "partial/oidc/admin/authorization_list.html" %}
{% include "partial/authorization_list.html" %}
{% endblock %}

View file

@ -40,5 +40,5 @@
{{ table.search(table_form, "table.clients") }}
</div>
{% include "partial/oidc/admin/client_list.html" %}
{% include "partial/client_list.html" %}
{% endblock %}

View file

@ -0,0 +1,46 @@
{% extends theme('base.html') %}
{% import 'macro/flask.html' as flask %}
{% import 'macro/form.html' as fui %}
{% import 'partial/login_field.html' as login_field %}
{% block container %}
<div class="ui container" hx-boost="false">
<div class="content">
<div class="ui clearing segment">
{% if logo_url %}
<a href="{{ url_for('core.account.index') }}">
<img class="ui tiny centered image" src="{{ logo_url }}" alt="{{ website_name }}">
</a>
{% else %}
<i class="massive sign in icon image ui"></i>
{% endif %}
<h2 class="ui center aligned header">
<div class="content">
{{ _("Sign in at %(website)s", website=website_name) }}
</div>
<div class="sub header">{% trans %}Manage your information and your authorizations{% endtrans %}</div>
</h2>
{{ flask.messages() }}
{% call fui.render_form(form) %}
{% block login_field scoped %}{{ login_field.render_field(form.login, class="autofocus") }}{% endblock %}
{% if "password" in form %}
{% block password_field scoped %}{{ login_field.render_field(form.password) }}{% endblock %}
{% endif %}
<div class="ui right aligned container">
<div class="ui stackable buttons">
{% if has_smtp and has_password_recovery %}
<a type="button" class="ui right floated button" href="{{ url_for('core.account.forgotten') }}">{{ _("Forgotten password") }}</a>
{% endif %}
<button type="submit" name="answer" class="ui right floated primary button" hx-boost="false">{{ _("Continue") }}</button>
</div>
</div>
{% endcall %}
</div>
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,9 @@
{% import 'macro/form.html' as fui %}
{% macro render_field(field) %}
{% if field.name == "login" %}
{{ fui.render_field(field, icon="user", noindicator=true, class="autofocus", **kwargs) }}
{% endif %}
{% if field.name == "password" %}
{{ fui.render_field(field, icon="key", noindicator=true, **kwargs) }}
{% endif %}
{% endmacro %}

View file

@ -40,5 +40,5 @@
{{ table.search(table_form, "table.tokens") }}
</div>
{% include "partial/oidc/admin/token_list.html" %}
{% include "partial/token_list.html" %}
{% endblock %}

View file

@ -23,7 +23,7 @@ def index(user):
abort(404)
return render_htmx_template(
"oidc/admin/token_list.html", menuitem="admin", table_form=table_form
"token_list.html", menuitem="admin", table_form=table_form
)
@ -45,7 +45,7 @@ def view(user, token):
abort(400, f"bad form action: {request.form.get('action')}")
return render_template(
"oidc/admin/token_view.html",
"token_view.html",
token=token,
menuitem="admin",
form=form,