From 123bea3c403f7b2bb11a6920faa7248da34a5f42 Mon Sep 17 00:00:00 2001 From: Stuart Wade Date: Wed, 8 Jun 2016 12:01:09 -0300 Subject: [PATCH 1/3] TWO_FACTOR_SKIP_WELCOME setting to skip welcome page. --- two_factor/views/core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/two_factor/views/core.py b/two_factor/views/core.py index ab9cff04f..8922fba2b 100644 --- a/two_factor/views/core.py +++ b/two_factor/views/core.py @@ -204,7 +204,7 @@ class SetupView(IdempotentSessionWizardView): template_name = 'two_factor/core/setup.html' session_key_name = 'django_two_factor-qr_secret_key' initial_dict = {} - form_list = ( + form_list = [ ('welcome', Form), ('method', MethodForm), ('generator', TOTPDeviceForm), @@ -212,7 +212,11 @@ class SetupView(IdempotentSessionWizardView): ('call', PhoneNumberForm), ('validation', DeviceValidationForm), ('yubikey', YubiKeyDeviceForm), - ) + ] + if hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') and settings.TWO_FACTOR_SKIP_WELCOME: + form_list.pop(0) + form_list = tuple(form_list) + condition_dict = { 'generator': lambda self: self.get_method() == 'generator', 'call': lambda self: self.get_method() == 'call', From 4f13c249fae1ff2753f8de2e5525fc85029bf302 Mon Sep 17 00:00:00 2001 From: Stuart Wade Date: Thu, 7 Jul 2016 11:49:08 -0300 Subject: [PATCH 2/3] Using condition_dict to skip welcome page according to settings --- two_factor/views/core.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/two_factor/views/core.py b/two_factor/views/core.py index 8922fba2b..15438fea8 100644 --- a/two_factor/views/core.py +++ b/two_factor/views/core.py @@ -204,7 +204,7 @@ class SetupView(IdempotentSessionWizardView): template_name = 'two_factor/core/setup.html' session_key_name = 'django_two_factor-qr_secret_key' initial_dict = {} - form_list = [ + form_list = ( ('welcome', Form), ('method', MethodForm), ('generator', TOTPDeviceForm), @@ -212,12 +212,10 @@ class SetupView(IdempotentSessionWizardView): ('call', PhoneNumberForm), ('validation', DeviceValidationForm), ('yubikey', YubiKeyDeviceForm), - ] - if hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') and settings.TWO_FACTOR_SKIP_WELCOME: - form_list.pop(0) - form_list = tuple(form_list) + ) condition_dict = { + 'welcome': lambda self: not hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') or not settings.TWO_FACTOR_SKIP_WELCOME, 'generator': lambda self: self.get_method() == 'generator', 'call': lambda self: self.get_method() == 'call', 'sms': lambda self: self.get_method() == 'sms', From 0e74905c131c05f601eeeff883e0f21d1c9cb25f Mon Sep 17 00:00:00 2001 From: Stuart Wade Date: Thu, 7 Jul 2016 12:20:42 -0300 Subject: [PATCH 3/3] Fixed pep8 linting complaint --- two_factor/views/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/two_factor/views/core.py b/two_factor/views/core.py index 15438fea8..5506748d6 100644 --- a/two_factor/views/core.py +++ b/two_factor/views/core.py @@ -214,8 +214,9 @@ class SetupView(IdempotentSessionWizardView): ('yubikey', YubiKeyDeviceForm), ) + show_welcome = not hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') or not settings.TWO_FACTOR_SKIP_WELCOME condition_dict = { - 'welcome': lambda self: not hasattr(settings, 'TWO_FACTOR_SKIP_WELCOME') or not settings.TWO_FACTOR_SKIP_WELCOME, + 'welcome': lambda self: show_welcome, 'generator': lambda self: self.get_method() == 'generator', 'call': lambda self: self.get_method() == 'call', 'sms': lambda self: self.get_method() == 'sms',