# HG changeset patch # User Peter Sanchez # Date 1599697197 25200 # Wed Sep 09 17:19:57 2020 -0700 # Node ID 464896a03132e6339293b606aab04ae13dcdbde2 # Parent 203dac1b027b8ae3dc62a439d7f66e23ff701ee3 Running code through black diff --git a/nlotp/apps.py b/nlotp/apps.py --- a/nlotp/apps.py +++ b/nlotp/apps.py @@ -13,14 +13,12 @@ checks.Tags.required_installed_apps, ) register( - checks.check_required_settings, - checks.Tags.required_settings, + checks.check_required_settings, checks.Tags.required_settings, ) register( checks.check_required_middlewares, checks.Tags.required_middlewares, ) register( - checks.check_suggested_settings, - checks.Tags.suggested_settings, + checks.check_suggested_settings, checks.Tags.suggested_settings, ) diff --git a/nlotp/forms.py b/nlotp/forms.py --- a/nlotp/forms.py +++ b/nlotp/forms.py @@ -8,31 +8,31 @@ class TokenForm(OTPTokenForm): def __init__(self, user, request=None, *args, **kwargs): super().__init__(user, request, *args, **kwargs) - self.fields['otp_device'].widget = forms.HiddenInput() + self.fields["otp_device"].widget = forms.HiddenInput() try: - self.fields['otp_device'].initial = self.fields[ - 'otp_device' + self.fields["otp_device"].initial = self.fields[ + "otp_device" ].choices[0][0] except IndexError: pass self.otp_error_messages.update( { - 'invalid_token': ( - 'Invalid code. ' - 'Please make sure you have entered it correctly.' + "invalid_token": ( + "Invalid code. " + "Please make sure you have entered it correctly." ), - 'token_required': 'Please enter your code.', + "token_required": "Please enter your code.", } ) def clean_otp(self, user): if user is None: return - token = self.cleaned_data.get('otp_token') + token = self.cleaned_data.get("otp_token") if not token: raise forms.ValidationError( - self.otp_error_messages['token_required'], - code='token_required', + self.otp_error_messages["token_required"], + code="token_required", ) user.otp_device = None exception = None @@ -52,39 +52,39 @@ class TwoFactorAuthForm(forms.ModelForm): authentication_code = forms.CharField(required=False) password = forms.CharField( - label='Account Password', - widget=forms.PasswordInput(attrs={'class': 'short text'}), + label="Account Password", + widget=forms.PasswordInput(attrs={"class": "short text"}), max_length=25, required=False, ) class Meta: model = get_user_model() - fields = ('authentication_code', 'password') + fields = ("authentication_code", "password") def __init__(self, *args, **kwargs): - self.user = kwargs.get('instance') - self.device = kwargs.pop('device') - self.generate_codes = kwargs.pop('generate_codes') + self.user = kwargs.get("instance") + self.device = kwargs.pop("device") + self.generate_codes = kwargs.pop("generate_codes") super().__init__(*args, **kwargs) - self.fields['password'].help_text = ( - 'To disable 2FA or to generate new backup codes, you must enter ' - 'your account password here and click the appropriate button below' + self.fields["password"].help_text = ( + "To disable 2FA or to generate new backup codes, you must enter " + "your account password here and click the appropriate button below" ) def clean(self): if not self.device.confirmed and not self.generate_codes: - auth_code = self.cleaned_data['authentication_code'] + auth_code = self.cleaned_data["authentication_code"] if not auth_code: raise forms.ValidationError( - 'Please provide the authentication code for ' - 'Time Based One-Time Password' + "Please provide the authentication code for " + "Time Based One-Time Password" ) else: - password = self.cleaned_data['password'] + password = self.cleaned_data["password"] if not self.user.check_password(password): raise forms.ValidationError( - 'Password is not valid, please provide ' - 'your account password.' + "Password is not valid, please provide " + "your account password." ) return self.cleaned_data diff --git a/nlotp/settings.py b/nlotp/settings.py --- a/nlotp/settings.py +++ b/nlotp/settings.py @@ -4,44 +4,32 @@ # 2FA verify page url NLOTP_VERIFY_URL = getattr( - settings, - "NLOTP_VERIFY_URL", - reverse_lazy("nlotp:verify-otp"), + settings, "NLOTP_VERIFY_URL", reverse_lazy("nlotp:verify-otp"), ) # list of urls excluded from redirect to verify page if user is not verified # NOTE: login and logout views should be added to this list NLOTP_VERIFY_EXCLUDED_URLS = getattr( - settings, - "NLOTP_VERIFY_EXCLUDED_URLS", - ( - NLOTP_VERIFY_URL, - ), + settings, "NLOTP_VERIFY_EXCLUDED_URLS", (NLOTP_VERIFY_URL,), ) # if 2FA setup is mandatory NLOTP_2FA_SETUP_REQUIRED = getattr( - settings, - "NLOTP_2FA_SETUP_REQUIRED", - False, + settings, "NLOTP_2FA_SETUP_REQUIRED", False, ) # 2FA setup page url NLOTP_2FA_SETUP_URL = getattr( - settings, - "NLOTP_2FA_SETUP_URL", - reverse_lazy("nlotp:two-factor-auth"), + settings, "NLOTP_2FA_SETUP_URL", reverse_lazy("nlotp:two-factor-auth"), ) # user TOTP device QR code generation url NLOTP_QR_CODE_URL = getattr( - settings, - "NLOTP_QR_CODE_URL", - reverse_lazy("nlotp:qr-code"), + settings, "NLOTP_QR_CODE_URL", reverse_lazy("nlotp:qr-code"), ) @@ -51,8 +39,5 @@ NLOTP_SETUP_EXCLUDED_URLS = getattr( settings, "NLOTP_SETUP_EXCLUDED_URLS", - ( - NLOTP_2FA_SETUP_URL, - NLOTP_QR_CODE_URL, - ), + (NLOTP_2FA_SETUP_URL, NLOTP_QR_CODE_URL,), ) diff --git a/nlotp/urls.py b/nlotp/urls.py --- a/nlotp/urls.py +++ b/nlotp/urls.py @@ -2,22 +2,14 @@ from . import views -app_name = 'nlotp' +app_name = "nlotp" urlpatterns = [ - path( - 'qr-code/', - views.QRCodeView.as_view(), - name='qr-code', - ), + path("qr-code/", views.QRCodeView.as_view(), name="qr-code",), + path("verify/", views.VerifyOTPView.as_view(), name="verify-otp",), path( - 'verify/', - views.VerifyOTPView.as_view(), - name='verify-otp', - ), - path( - 'two-factor-auth/', + "two-factor-auth/", views.TwoFactorAuthView.as_view(), - name='two-factor-auth', + name="two-factor-auth", ), ]