| 1 |
{# |
| 2 |
This template receives different input based on state of tf-setup. In addition |
| 3 |
to form values the following are available: |
| 4 |
On GET or unsuccessful POST: |
| 5 |
choices: Value of SECURITY_TWO_FACTOR_ENABLED_METHODS (with possible addition of 'disable') |
| 6 |
two_factor_required: Value of SECURITY_TWO_FACTOR_REQUIRED (or result from user.tf_check_required_setup) |
| 7 |
primary_method: the translated name of two-factor method that has already been set up. |
| 8 |
On successful POST: |
| 9 |
chosen_method: which 2FA method was chosen (e.g. sms, authenticator) |
| 10 |
choices: Value of SECURITY_TWO_FACTOR_ENABLED_METHODS |
| 11 |
changing: boolean - True if user is trying to change/disable 2FA |
| 12 |
state_token: if changing - this is the new (non-session) way to validate |
| 13 |
the new 2FA method |
| 14 |
|
| 15 |
If chosen_method == 'authenticator': |
| 16 |
authr_qrcode: the image source for the qrcode |
| 17 |
authr_key: same key as in qrcode - for possible manual entry |
| 18 |
authr_username: same username as in qrcode |
| 19 |
authr_issuer: same issuer as in qrcode |
| 20 |
#} |
| 21 |
{% set title = title|default(_fsdomain("Two-Factor Setup")) %} |
| 22 |
{% extends "security/base.html" %} |
| 23 |
{% from "security/_macros.html" import render_field_with_errors, render_field, |
| 24 |
render_field_no_label, render_field_errors, render_form_errors, render_csrf %} |
| 25 |
|
| 26 |
{% block content %} |
| 27 |
{% include "security/_messages.html" %} |
| 28 |
<h1>{{ _fsdomain("Two-Factor authentication adds an extra layer of security to your account") }}</h1> |
| 29 |
<h3>{{ _fsdomain("In addition to your username and password, you'll need to use a code.") }}</h3> |
| 30 |
<form action="{{ url_for_security('two_factor_setup') }}" method="post" name="two_factor_setup_form"> |
| 31 |
{{ two_factor_setup_form.hidden_tag() }} |
| 32 |
{{ render_form_errors(two_factor_setup_form) }} |
| 33 |
<div class="fs-div">{{ _fsdomain("Currently setup two-factor method: %(method)s", method=primary_method) }}</div> |
| 34 |
<hr class="fs-gap"> |
| 35 |
{% for subfield in two_factor_setup_form.setup %} |
| 36 |
{% if subfield.data in choices %}{{ render_field_with_errors(subfield) }}{% endif %} |
| 37 |
{% endfor %} |
| 38 |
<div class="fs-div"> |
| 39 |
{% if "sms" in choices %} |
| 40 |
{{ render_field_with_errors(two_factor_setup_form.phone) }} |
| 41 |
{% endif %} |
| 42 |
</div> |
| 43 |
<div class="fs-gap"> |
| 44 |
{{ render_field_errors(two_factor_setup_form.setup) }} |
| 45 |
{{ render_field_errors(two_factor_setup_form.csrf_token) }} |
| 46 |
{{ render_field(two_factor_setup_form.submit) }} |
| 47 |
</div> |
| 48 |
{% if chosen_method=="authenticator" %} |
| 49 |
<hr> |
| 50 |
<div class="fs-center"> |
| 51 |
<div> |
| 52 |
{{ _fsdomain("Open an authenticator app on your device and scan the following QRcode (or enter the code below manually) to start receiving codes:") }} |
| 53 |
</div> |
| 54 |
<div> |
| 55 |
<img alt="{{ _fsdomain('Two-Factor authentication code') }}" id="qrcode" src="{{ authr_qrcode }}"> |
| 56 |
{# TODO: add width and height attrs #} |
| 57 |
</div> |
| 58 |
<div>{{ authr_key }}</div> |
| 59 |
</div> |
| 60 |
{% endif %} |
| 61 |
</form> |
| 62 |
{% if chosen_method %} |
| 63 |
{# Hide this when first setting up #} |
| 64 |
{# This is the fill in code part #} |
| 65 |
<hr class="fs-gap"> |
| 66 |
<div class="fs-important">{{ _fsdomain("Enter code to complete setup") }}</div> |
| 67 |
{% if changing %} |
| 68 |
{% set faction = url_for_security('two_factor_setup_validate', token=state_token) %} |
| 69 |
{% else %} |
| 70 |
{% set faction = url_for_security('two_factor_token_validation') %} |
| 71 |
{% endif %} |
| 72 |
<form action="{{ faction }}" method="post" name="two_factor_verify_code_form"> |
| 73 |
{# explicitly render csrf_token so we can change the ID so we don't get duplicates #} |
| 74 |
{{ render_csrf(two_factor_verify_code_form, "code") }} |
| 75 |
{{ render_field_with_errors(two_factor_verify_code_form.code, placeholder=_fsdomain("enter numeric code")) }} |
| 76 |
<div class="fs-gap">{{ render_field(two_factor_verify_code_form.submit) }}</div> |
| 77 |
</form> |
| 78 |
{% else %} |
| 79 |
{% if security.support_mfa and security.multi_factor_recovery_codes %} |
| 80 |
<hr class="fs-gap"> |
| 81 |
<h3>{{ _fsdomain("Recovery Codes") }}</h3> |
| 82 |
<div class="fs-div"> |
| 83 |
{{ _fsdomain("This application supports setting up recovery codes.") }} |
| 84 |
<a href="{{ url_for_security('mf_recovery_codes') }}">{{ _fsdomain("You can set them up here.") }}</a> |
| 85 |
</div> |
| 86 |
{% endif %} |
| 87 |
{% if security.webauthn %} |
| 88 |
<hr class="fs-gap"> |
| 89 |
<h3>{{ _fsdomain("Passkeys") }}</h3> |
| 90 |
<div class="fs-div"> |
| 91 |
{{ _fsdomain("This application supports passkeys.") }} |
| 92 |
<a href="{{ url_for_security('wan_register') }}">{{ _fsdomain("You can set them up here.") }}</a> |
| 93 |
</div> |
| 94 |
{% endif %} |
| 95 |
{% endif %} |
| 96 |
|
| 97 |
{% include "security/_menu.html" %} |
| 98 |
{% endblock content %} |