Skip to content

Commit 1786bdd

Browse files
authored
[HIDP-235] Add logout option if unable to verify or setup device (#338)
2 parents 3e1bfb5 + 9e29a96 commit 1786bdd

File tree

7 files changed

+47
-13
lines changed

7 files changed

+47
-13
lines changed

packages/hidp/hidp/locale/django.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,10 @@ msgid_plural "Your account is currently linked with the following services:"
804804
msgstr[0] ""
805805
msgstr[1] ""
806806

807+
#: hidp/templates/hidp/includes/forms/logout_form.html
808+
msgid "Cancel and return to login"
809+
msgstr ""
810+
807811
#: hidp/templates/hidp/otp/disable.html
808812
#: hidp/templates/hidp/otp/disable_recovery_code.html
809813
msgid "Disable two-factor authentication"

packages/hidp/hidp/locale/nl/LC_MESSAGES/django.po

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,10 @@ msgid_plural "Your account is currently linked with the following services:"
805805
msgstr[0] "Je account is momenteel aan de volgende dienst gekoppeld:"
806806
msgstr[1] "Je account is momenteel aan de volgende diensten gekoppeld:"
807807

808+
#: hidp/templates/hidp/includes/forms/logout_form.html
809+
msgid "Cancel and return to login"
810+
msgstr "Annuleren en terug naar inloggen"
811+
808812
#: hidp/templates/hidp/otp/disable.html
809813
#: hidp/templates/hidp/otp/disable_recovery_code.html
810814
msgid "Disable two-factor authentication"

packages/hidp/hidp/otp/views.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ def get_form_kwargs(self):
201201
return kwargs
202202

203203
def get_context_data(self, **kwargs):
204-
context = super().get_context_data(**kwargs)
205-
206-
return context | {
204+
context = {
207205
"title": _("Set up two-factor authentication"),
208206
"device": self.device,
209207
"backup_device": self.backup_device,
@@ -213,7 +211,9 @@ def get_context_data(self, **kwargs):
213211
self.backup_device.token_set.values_list("token", flat=True)
214212
),
215213
"back_url": reverse("hidp_otp_management:manage"),
214+
"logout_url": reverse("hidp_accounts:logout"),
216215
}
216+
return super().get_context_data() | context | kwargs
217217

218218
def form_valid(self, form):
219219
form.save()
@@ -280,9 +280,11 @@ def get_recovery_code_url(self, request): # noqa: PLR6301
280280
return base_url
281281

282282
def get_context_data(self, **kwargs):
283-
context = super().get_context_data(**kwargs)
284-
context["recovery_code_url"] = self.get_recovery_code_url(self.request)
285-
return context
283+
context = {
284+
"recovery_code_url": self.get_recovery_code_url(self.request),
285+
"logout_url": reverse("hidp_accounts:logout"),
286+
}
287+
return super().get_context_data() | context | kwargs
286288

287289

288290
class VerifyRecoveryCodeView(VerifyOTPBase):
@@ -296,6 +298,10 @@ def form_valid(self, form):
296298

297299
return result
298300

301+
def get_context_data(self, **kwargs):
302+
context = {"logout_url": reverse("hidp_accounts:logout")}
303+
return super().get_context_data() | context | kwargs
304+
299305
def send_mail(self):
300306
"""Notify the user that a recovery code was used."""
301307
base_url = self.request.build_absolute_uri("/")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% load i18n %}
2+
{% comment %}
3+
The logout_url is required for the form action. It is passed in from the view
4+
that renders this template. If the logout_url is not provided, the form will not
5+
be rendered.
6+
{% endcomment %}
7+
{% if logout_url %}
8+
<form action="{{ logout_url }}" method="post">
9+
{% csrf_token %}
10+
<button type="submit">
11+
{{ logout_label|default:_("Cancel and return to login") }}
12+
</button>
13+
</form>
14+
{% endif %}

packages/hidp/hidp/templates/hidp/otp/setup_device.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ <h2>{% translate 'Recovery codes' %}</h2>
6666
{{ form.confirm_stored_backup_tokens }}
6767
</p>
6868

69-
{% include 'hidp/includes/forms/submit_row.html' with submit_label=_('Submit') cancel_label=_('Back') cancel_url=back_url %}
69+
{% include 'hidp/includes/forms/submit_row.html' with submit_label=_('Submit') %}
7070
</form>
71+
72+
{% include 'hidp/includes/forms/logout_form.html' %}
73+
<a href="{{ back_url }}">{% translate 'Back' %}</a>
7174
{% endblock %}

packages/hidp/hidp/templates/hidp/otp/verify.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
<h1>{% translate 'Two-factor authentication' %}</h1>
88

99
<form method="post">
10-
{% csrf_token %}
11-
{{ form }}
10+
{% csrf_token %}
11+
{{ form }}
1212

13-
{% include 'hidp/includes/forms/submit_row.html' with submit_label=_('Verify') %}
13+
{% include 'hidp/includes/forms/submit_row.html' with submit_label=_('Verify') %}
1414
</form>
1515

16+
{% include 'hidp/includes/forms/logout_form.html' %}
17+
1618
<p>
1719
{% blocktranslate trimmed %}
1820
If you have lost your device, you can <a href="{{ recovery_code_url }}">use a recovery code</a> instead.

packages/hidp/hidp/templates/hidp/otp/verify_recovery_code.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
<h1>{% translate 'Two-factor authentication' %}</h1>
88

99
<form method="post">
10-
{% csrf_token %}
11-
{{ form }}
10+
{% csrf_token %}
11+
{{ form }}
1212

13-
{% include 'hidp/includes/forms/submit_row.html' with submit_label=_('Verify') %}
13+
{% include 'hidp/includes/forms/submit_row.html' with submit_label=_('Verify') %}
1414
</form>
1515

16+
{% include 'hidp/includes/forms/logout_form.html' %}
1617
{% endblock %}

0 commit comments

Comments
 (0)