From 4f44f5c70d57a19efe2b4de190b8991c92f7b54b Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Tue, 4 Sep 2018 17:54:15 -0700 Subject: [PATCH] Move 2FA settings template logic into view, add help text Move the logic required to split the key into groups from the template into the view. Additionally add some helper text to indicate how to use the key. --- tildes/tildes/templates/settings_two_factor.jinja2 | 9 +++------ tildes/tildes/views/settings.py | 5 ++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tildes/tildes/templates/settings_two_factor.jinja2 b/tildes/tildes/templates/settings_two_factor.jinja2 index c947a21..60c993a 100644 --- a/tildes/tildes/templates/settings_two_factor.jinja2 +++ b/tildes/tildes/templates/settings_two_factor.jinja2 @@ -29,12 +29,9 @@

Next, scan the below QR code with the app of your choice.

-{% set chunk_size = 4 %} -

-{% for i in range (0, two_factor_secret|length, chunk_size) %} -{{ two_factor_secret[i:i+chunk_size] }} -{% endfor %} -

+ +

If you are unable to scan the QR code, you can enter the following key: +

{{ two_factor_secret }}

Lastly, enter the 6-digit code displayed in the app.

diff --git a/tildes/tildes/views/settings.py b/tildes/tildes/views/settings.py index 2932a6c..e12c906 100644 --- a/tildes/tildes/views/settings.py +++ b/tildes/tildes/views/settings.py @@ -10,6 +10,7 @@ from pyramid.view import view_config import qrcode from webargs.pyramidparser import use_kwargs +from tildes.lib.string import separate_string from tildes.schemas.user import EMAIL_ADDRESS_NOTE_MAX_LENGTH, UserSchema @@ -56,7 +57,9 @@ def get_settings_two_factor(request: Request) -> dict: if request.user.two_factor_secret is None: request.user.two_factor_secret = pyotp.random_base32() - return {"two_factor_secret": request.user.two_factor_secret} + return { + "two_factor_secret": separate_string(request.user.two_factor_secret, " ", 4) + } @view_config(