diff --git a/src/wagtail_2fa/templates/wagtail_2fa/legacy/otp_form.html b/src/wagtail_2fa/templates/wagtail_2fa/legacy/otp_form.html new file mode 100644 index 0000000..0ab65bd --- /dev/null +++ b/src/wagtail_2fa/templates/wagtail_2fa/legacy/otp_form.html @@ -0,0 +1,74 @@ +{% extends "wagtailadmin/admin_base.html" %} +{% load static i18n %} +{% block titletag %}{% trans "Sign in" %}{% endblock %} +{% block bodyclass %}login{% endblock %} + +{% block extra_css %} + {{ block.super }} + + +{% endblock %} + +{% block furniture %} +
+ {% if messages or form.errors %} +
+ +
+ {% endif %} + + {% block above_login %}{% endblock %} + +
+ {% block login_form %} + {% csrf_token %} + + {% url 'wagtailadmin_home' as home_url %} + + +

{% block branding_login %}{% trans "Enter your two-factor authentication code" %}{% endblock %}

+ + + {% endblock %} +
+ + {% block below_login %}{% endblock %} + +
+{% endblock %} diff --git a/src/wagtail_2fa/templates/wagtail_2fa/otp_form.html b/src/wagtail_2fa/templates/wagtail_2fa/otp_form.html index 0ab65bd..fabe5b0 100644 --- a/src/wagtail_2fa/templates/wagtail_2fa/otp_form.html +++ b/src/wagtail_2fa/templates/wagtail_2fa/otp_form.html @@ -1,18 +1,15 @@ {% extends "wagtailadmin/admin_base.html" %} -{% load static i18n %} +{% load i18n wagtailadmin_tags %} {% block titletag %}{% trans "Sign in" %}{% endblock %} {% block bodyclass %}login{% endblock %} -{% block extra_css %} - {{ block.super }} - - -{% endblock %} - {% block furniture %} -
- {% if messages or form.errors %} -
+
+

{% block branding_login %}{% trans "Enter your two-factor authentication code" %}{% endblock %}

+ +
+ {# Always show messages div so it can be appended to by JS #} + {% if messages or form.errors %}
    {% if form.errors %}
  • {% blocktrans %}Invalid code{% endblocktrans %}
  • @@ -21,54 +18,43 @@
  • {{ message }}
  • {% endfor %}
-
- {% endif %} + {% endif %} +
{% block above_login %}{% endblock %}
{% block login_form %} - {% csrf_token %} + {% csrf_token %} - {% url 'wagtailadmin_home' as home_url %} - + {% url 'wagtailadmin_home' as home_url %} + -

{% block branding_login %}{% trans "Enter your two-factor authentication code" %}{% endblock %}

- - - {% endblock %} + {% endblock %} +
{% block below_login %}{% endblock %} -
+ {% block branding_logo %} + + {% endblock %} + {% endblock %} diff --git a/src/wagtail_2fa/views.py b/src/wagtail_2fa/views.py index 67ddc58..88b931c 100644 --- a/src/wagtail_2fa/views.py +++ b/src/wagtail_2fa/views.py @@ -23,12 +23,16 @@ from django_otp import login as otp_login from django_otp.plugins.otp_totp.models import TOTPDevice +from wagtail import VERSION as WAGTAIL_VERSION from wagtail_2fa import forms, utils from wagtail_2fa.mixins import OtpRequiredMixin class LoginView(RedirectURLMixin, FormView): - template_name = "wagtail_2fa/otp_form.html" + if WAGTAIL_VERSION >= (4, 0, 0): + template_name = "wagtail_2fa/otp_form.html" + else: + template_name = "wagtail_2fa/legacy/otp_form.html" form_class = forms.TokenForm redirect_field_name = REDIRECT_FIELD_NAME