|
| 1 | +{# |
| 2 | + Altered login form that includes the 2FA authentication. |
| 3 | +#} |
| 4 | + |
1 | 5 | {% import 'macros/form.html' as form %} |
2 | 6 |
|
3 | 7 | {% set username_error = true if error_summary %} |
4 | 8 | {% set password_error = true if error_summary %} |
| 9 | +{% set is_2fa_enabled = h.is_2fa_enabled() %} |
5 | 10 |
|
6 | | -<form action="{{ action }}" method="post"> |
| 11 | +<form |
| 12 | + id="mfa-login-form" action="{{ action }}" method="post" |
| 13 | + data-module="auth-login-form" |
| 14 | + data-module-enabled="{{ h.is_2fa_enabled() | tojson }}" |
| 15 | + data-module-mfa-method="{{ h.get_2fa_method() }}"> |
7 | 16 | {{ h.csrf_input() }} |
8 | 17 | {{ form.errors(errors=error_summary) }} |
9 | 18 |
|
10 | | - {{ form.input('login', label=_("Username or Email"), id='field-login', value="", error=username_error, classes=["control-medium"]) }} |
| 19 | + <div id="error-container" class="alert alert-error" style="display: none;"> |
| 20 | + <p>{{ _('The form contains invalid entries:') }}</p> |
| 21 | + <ul> |
| 22 | + <li id="error-message"></li> |
| 23 | + </ul> |
| 24 | + </div> |
| 25 | + |
| 26 | + <div id="login-form"> |
| 27 | + {{ form.input('login', label=_("Username or Email"), id='field-login', value="", error=username_error, classes=["control-medium"]) }} |
11 | 28 |
|
12 | | - {{ form.input('password', label=_("Password"), id='field-password', type="password", value="", error=password_error, classes=["control-medium"]) }} |
| 29 | + {{ form.input('password', label=_("Password"), id='field-password', type="password", value="", error=password_error, classes=["control-medium"]) }} |
13 | 30 |
|
14 | | - {{ form.checkbox('remember', label=_("Remember me"), id='field-remember', checked=true, value="63072000") }} |
| 31 | + {{ form.checkbox('remember', label=_("Remember me"), id='field-remember', checked=true, value="63072000") }} |
15 | 32 |
|
16 | | - {% if g.recaptcha_publickey %} |
17 | | - {% snippet "user/snippets/recaptcha.html", public_key=g.recaptcha_publickey %} |
18 | | - {% endif %} |
| 33 | + {% if g.recaptcha_publickey %} |
| 34 | + {% snippet "user/snippets/recaptcha.html", public_key=g.recaptcha_publickey %} |
| 35 | + {% endif %} |
19 | 36 |
|
20 | | - <div class="form-actions"> |
21 | | - {% block login_button %} |
22 | | - <button class="btn btn-primary" type="submit">{{ _('Login') }}</button> |
23 | | - {% endblock %} |
| 37 | + <div class="form-actions"> |
| 38 | + {% block login_button %} |
| 39 | + {% if is_2fa_enabled %} |
| 40 | + <button class="btn btn-primary" id="mfa-next">{{ _('Next') }}</button> |
| 41 | + {% else %} |
| 42 | + <button class="btn btn-primary" type="submit">{{ _('Login') }}</button> |
| 43 | + {% endif %} |
| 44 | + {% endblock %} |
| 45 | + </div> |
24 | 46 | </div> |
| 47 | + |
| 48 | + {% if is_2fa_enabled %} |
| 49 | + <input id="mfa-type" name="mfa_type" type="hidden" value="{{ h.get_2fa_method() }}" /> |
| 50 | + |
| 51 | + {% if h.is_totp_2fa_enabled() %} |
| 52 | + <div id="mfa-form" style="display: none;"> |
| 53 | + <fieldset id="mfa-setup" style="display: none;"> |
| 54 | + <legend>{{_('Scan this QR code with your two factor authentication app')}}</legend> |
| 55 | + <p>{% trans %}If you don't already have an authenticator app, you could try Google Authenticator.{% endtrans %}</p> |
| 56 | + |
| 57 | + <div> |
| 58 | + <canvas class="radius-lg padding-sm margin-b-sm border-solid" data-module="auth-qr-render"></canvas> |
| 59 | + </div> |
| 60 | + |
| 61 | + <p> |
| 62 | + {%- trans -%}If you are not able to scan the QR code, you can manually enter this secret into your |
| 63 | + authenticator app: {%- endtrans -%}<code id="totp-secret"></code> |
| 64 | + </p> |
| 65 | + </fieldset> |
| 66 | + |
| 67 | + <p>{{_('Please enter your authenticator app generated 6-digit verification code.')}}</p> |
| 68 | + {{ form.input('code', label=_("Verification code"), id='field-mfa', type="text", value="", error=mfa_error, |
| 69 | + classes=["control-medium"], attrs={"autocomplete": "off", 'class': 'form-control', 'required': 1}) }} |
| 70 | + |
| 71 | + <input id="mfa-form-active" name="mfa-form-active" type="hidden" value="" /> |
| 72 | + <div class="form-actions"> |
| 73 | + <a id="mfa-help-link" href="/" style="display: none; margin-right: 20px;">{{_('Need help?')}}</a> |
| 74 | + <button class="btn btn-primary" id="mfa-submit">{{ _('Submit') }}</button> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + {% else %} |
| 78 | + <div id="mfa-form" style="display: none;"> |
| 79 | + <p>{{ _("We've just sent a verification code to your email.") }}</p> |
| 80 | + |
| 81 | + {{ form.input('code', label=_("Verification code"), id='field-mfa', type="text", value="", error=mfa_error, |
| 82 | + classes=["control-medium"], attrs={"autocomplete": "off", 'class': 'form-control'}) }} |
| 83 | + |
| 84 | + <p>{{ _("Didn't get it?") }} |
| 85 | + <button id="resend-mfa" class="btn btn-default mx-2" type="button"> |
| 86 | + {{ _("Resend code") }} |
| 87 | + <span class="counter"></span> |
| 88 | + </button> |
| 89 | + </p> |
| 90 | + |
| 91 | + <input id="mfa-form-active" name="mfa-form-active" type="hidden" value="" /> |
| 92 | + <div class="form-actions"> |
| 93 | + <a id="mfa-help-link" href="/" style="display: none; margin-right: 20px;">{{_('Need help?')}}</a> |
| 94 | + <button class="btn btn-primary" id="mfa-submit">{{ _('Submit') }}</button> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + {% endif %} |
| 98 | + {% endif %} |
25 | 99 | </form> |
0 commit comments