Skip to content

Commit 49eb049

Browse files
committed
SXDEDPCXZIC-347_DATAVIC-733 / add ckanext-auth ext
1 parent 6cd52da commit 49eb049

1 file changed

Lines changed: 85 additions & 11 deletions

File tree

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,99 @@
1+
{#
2+
Altered login form that includes the 2FA authentication.
3+
#}
4+
15
{% import 'macros/form.html' as form %}
26

37
{% set username_error = true if error_summary %}
48
{% set password_error = true if error_summary %}
9+
{% set is_2fa_enabled = h.is_2fa_enabled() %}
510

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() }}">
716
{{ h.csrf_input() }}
817
{{ form.errors(errors=error_summary) }}
918

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"]) }}
1128

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"]) }}
1330

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") }}
1532

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 %}
1936

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>
2446
</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 %}
2599
</form>

0 commit comments

Comments
 (0)