Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more localization for two-factor #885

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions flask_security/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
"sms_method": _("Set up using SMS"),
}

_tf_methods_xlate = {
"google_authenticator": _("Google Authenticator"),
"authenticator": _("Authenticator app"),
"email": _("Email"),
"mail": _("Email"),
"sms": _("SMS"),
None: _("None"),
}


class ValidatorMixin:
"""
Expand Down
4 changes: 2 additions & 2 deletions flask_security/templates/security/two_factor_setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
On GET:
choices: Value of SECURITY_TWO_FACTOR_ENABLED_METHODS (with possible addition of 'delete'
two_factor_required: Value of SECURITY_TWO_FACTOR_REQUIRED
primary_method: if a two-factor method has already been set up.
primary_method_xlated: if a two-factor method has already been set up.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree this is confusing - making this change now will break backward compatibility for applications with their own templates. From what I can see - there are no forms where the same value (primary_method) is used both as a key and as an informational piece of info (in other words - from your changes - we never have BOTH primary_method AND primary_method_xlated. So - lets favor keeping things compatible...

On successful POST:
chosen_method: which 2FA method was chosen (e.g. sms, authenticator)
choices: Value of SECURITY_TWO_FACTOR_ENABLED_METHODS
Expand All @@ -25,7 +25,7 @@ <h1>{{ _fsdomain("Two-factor authentication adds an extra layer of security to y
<h3>{{ _fsdomain("In addition to your username and password, you'll need to use a code.") }}</h3>
<form action="{{ url_for_security('two_factor_setup') }}" method="post" name="two_factor_setup_form">
{{ two_factor_setup_form.hidden_tag() }}
<div class="fs-div">{{ _fsdomain("Currently setup two-factor method: %(method)s", method=primary_method) }}</div>
<div class="fs-div">{{ _fsdomain("Currently setup two-factor method: %(method)s", method=primary_method_xlated) }}</div>
<hr class="fs-gap">
{% for subfield in two_factor_setup_form.setup %}
{% if subfield.data in choices %}{{ render_field_with_errors(subfield) }}{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain("Two-factor Authentication") }}</h1>
<h2>{{ _fsdomain("Please enter your authentication code generated via: %(method)s", method=chosen_method) }}</h2>
<h2>{{ _fsdomain("Please enter your authentication code generated via: %(method)s", method=chosen_method_xlated) }}</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - lets keep things compatible.

<form action="{{ url_for_security('two_factor_token_validation') }}{{ prop_next() }}" method="post" name="two_factor_verify_code_form">
{{ two_factor_verify_code_form.hidden_tag() }}
{{ render_field_with_errors(two_factor_verify_code_form.code, placeholder=_fsdomain("enter code")) }}
Expand Down
Loading