From 1087ce4a3c9bdc95977c70e1906e41d655eb1f7a Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Sun, 29 Aug 2021 22:43:11 +0200 Subject: [PATCH] Start login template refactor --- .../accounts/components/login-form.html | 73 +++++++++++++++++-- .../templates/accounts/views/login.html | 2 +- src/newsreader/accounts/views/auth.py | 4 +- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/src/newsreader/accounts/templates/accounts/components/login-form.html b/src/newsreader/accounts/templates/accounts/components/login-form.html index 87dceb9..3bfd952 100644 --- a/src/newsreader/accounts/templates/accounts/components/login-form.html +++ b/src/newsreader/accounts/templates/accounts/components/login-form.html @@ -1,17 +1,78 @@ {% extends "components/form/form.html" %} {% load i18n %} +{# TODO incorporate formtools wizard #} +{# TODO add support for other devices and backup tokens #} +{# see two_factor/templates/two_factor/core/login.html #} + +{% block intro %} +
+ {% if wizard.steps.current == 'auth' %} +

{% blocktrans %}Enter your credentials.{% endblocktrans %}

+ {% elif wizard.steps.current == 'token' %} + {% if device.method == 'call' %} +

+ {% blocktrans trimmed %} + We are calling your phone right now, please enter the digits you hear. + {% endblocktrans %} +

+ {% elif device.method == 'sms' %} +

+ {% blocktrans trimmed %} + We sent you a text message, please enter the tokens we sent. + {% endblocktrans %} +

+ {% else %} +

+ {% blocktrans trimmed %} + Please enter the tokens generated by your token generator. + {% endblocktrans %} +

+ {% endif %} + {% elif wizard.steps.current == 'backup' %} +

+ {% blocktrans trimmed %} + Use this form for entering backup tokens for logging in. + These tokens have been generated for you to print and keep safe. Please + enter one of these backup tokens to login to your account. + {% endblocktrans %} +

+ {% endif %} +
+{% endblock intro %} + +{# TODO test this #} +{% block fields %} + {{ wizard.management_form }} + {{ block.super }} +{% endblock fields %} + {% block actions %}
- {% include "components/form/cancel-button.html" %} + {% if cancel_url %} + {% include "components/form/cancel-button.html" %} + {% endif %} + + {% if wizard.steps.prev %} + + {% else %} + + {% endif %} + {% include "components/form/confirm-button.html" %}
-
- - {% trans "I forgot my password" %} - -
+ {% if wizard.steps.index == wizard.steps.first %} +
+ + {% trans "I forgot my password" %} + +
+ {% endif %}
{% endblock actions %} diff --git a/src/newsreader/accounts/templates/accounts/views/login.html b/src/newsreader/accounts/templates/accounts/views/login.html index b4c391d..4e1f283 100644 --- a/src/newsreader/accounts/templates/accounts/views/login.html +++ b/src/newsreader/accounts/templates/accounts/views/login.html @@ -2,6 +2,6 @@ {% block content %}
- {% include "accounts/components/login-form.html" with form=form title="Login" confirm_text="Login" %} + {% include "accounts/components/login-form.html" with title="Login" confirm_text="Next" %}
{% endblock %} diff --git a/src/newsreader/accounts/views/auth.py b/src/newsreader/accounts/views/auth.py index 0663768..c478e26 100644 --- a/src/newsreader/accounts/views/auth.py +++ b/src/newsreader/accounts/views/auth.py @@ -1,8 +1,10 @@ from django.contrib.auth import views as django_views from django.urls import reverse_lazy +from two_factor import views as two_factor_views -class LoginView(django_views.LoginView): + +class LoginView(two_factor_views.LoginView): template_name = "accounts/views/login.html" success_url = reverse_lazy("index")