From ef7c2fef1bc0040d8aad43ab4bd041858f42f90d Mon Sep 17 00:00:00 2001 From: Sonny Bakker Date: Sat, 25 Sep 2021 09:54:06 +0200 Subject: [PATCH] Move 2 factor urls --- .../accounts/components/login-form.html | 4 +-- src/newsreader/accounts/urls.py | 32 +++++++++++++++++++ src/newsreader/accounts/views/auth.py | 10 ++++-- src/newsreader/conf/base.py | 3 +- src/newsreader/urls.py | 2 -- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/newsreader/accounts/templates/accounts/components/login-form.html b/src/newsreader/accounts/templates/accounts/components/login-form.html index 3bfd952..71f16ae 100644 --- a/src/newsreader/accounts/templates/accounts/components/login-form.html +++ b/src/newsreader/accounts/templates/accounts/components/login-form.html @@ -7,9 +7,7 @@ {% block intro %}
- {% if wizard.steps.current == 'auth' %} -

{% blocktrans %}Enter your credentials.{% endblocktrans %}

- {% elif wizard.steps.current == 'token' %} + {% if wizard.steps.current == 'token' %} {% if device.method == 'call' %}

{% blocktrans trimmed %} diff --git a/src/newsreader/accounts/urls.py b/src/newsreader/accounts/urls.py index 0eaee5c..c5b9944 100644 --- a/src/newsreader/accounts/urls.py +++ b/src/newsreader/accounts/urls.py @@ -1,6 +1,18 @@ from django.contrib.auth.decorators import login_required from django.urls import include, path +from two_factor.views import ( + BackupTokensView, + DisableView, + LoginView, + PhoneDeleteView, + PhoneSetupView, + ProfileView, + QRGeneratorView, + SetupCompleteView, + SetupView, +) + from newsreader.accounts.views import ( ActivationCompleteView, ActivationResendView, @@ -67,8 +79,28 @@ settings_patterns = [ path("", login_required(SettingsView.as_view()), name="home"), ] +two_factor = [ + path("accounts/setup/", SetupView.as_view(), name="setup"), + path("accounts/qrcode/", QRGeneratorView.as_view(), name="qr"), + path( + "accounts/setup/complete/", SetupCompleteView.as_view(), name="setup_complete" + ), + path("accounts/backup/tokens/", BackupTokensView.as_view(), name="backup_tokens"), + path( + "accounts/backup/phone/register/", PhoneSetupView.as_view(), name="phone_create" + ), + path( + "accounts/backup/phone/unregister//", + PhoneDeleteView.as_view(), + name="phone_delete", + ), + path("accounts/profile/", ProfileView.as_view(), name="profile"), + path("accounts/disable/", DisableView.as_view(), name="disable"), +] + urlpatterns = [ # Auth + path("", include((two_factor, "two_factor"))), path("login/", LoginView.as_view(), name="login"), path("logout/", LogoutView.as_view(), name="logout"), # Register diff --git a/src/newsreader/accounts/views/auth.py b/src/newsreader/accounts/views/auth.py index c478e26..8ec2895 100644 --- a/src/newsreader/accounts/views/auth.py +++ b/src/newsreader/accounts/views/auth.py @@ -1,12 +1,16 @@ from django.contrib.auth import views as django_views from django.urls import reverse_lazy -from two_factor import views as two_factor_views +from two_factor.views.core import LoginView as TwoFactorLoginView -class LoginView(two_factor_views.LoginView): +class LoginView(TwoFactorLoginView): + redirect_authenticated_user = True template_name = "accounts/views/login.html" - success_url = reverse_lazy("index") + + def post(self, *args, **kwargs): + print(self.request.POST) + return super().post(*args, **kwargs) class LogoutView(django_views.LogoutView): diff --git a/src/newsreader/conf/base.py b/src/newsreader/conf/base.py index c1f3b16..99f5b44 100644 --- a/src/newsreader/conf/base.py +++ b/src/newsreader/conf/base.py @@ -187,7 +187,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Authentication user model AUTH_USER_MODEL = "accounts.User" -LOGIN_URL = "two_factor:login" +LOGIN_URL = "accounts:login" LOGIN_REDIRECT_URL = "/" # Internationalization @@ -259,6 +259,7 @@ SWAGGER_SETTINGS = { # https://docs.celeryproject.org/en/stable/userguide/configuration.html CELERY_WORKER_HIJACK_ROOT_LOGGER = False +# Registration REGISTRATION_OPEN = True REGISTRATION_AUTO_LOGIN = True ACCOUNT_ACTIVATION_DAYS = 7 diff --git a/src/newsreader/urls.py b/src/newsreader/urls.py index 63879a6..e416d5d 100644 --- a/src/newsreader/urls.py +++ b/src/newsreader/urls.py @@ -6,7 +6,6 @@ from django.urls import include, path from drf_yasg import openapi from drf_yasg.views import get_schema_view from two_factor.admin import AdminSiteOTPRequired -from two_factor.urls import urlpatterns as two_factor_urls from newsreader.accounts.urls import urlpatterns as login_urls from newsreader.news.core.views import NewsView @@ -22,7 +21,6 @@ schema_view = get_schema_view(schema_info, patterns=api_patterns) admin.site.__class__ = AdminSiteOTPRequired urlpatterns = [ - path("", include(two_factor_urls)), path("", login_required(NewsView.as_view()), name="index"), path("", include((news_patterns, "news"))), path("", include((api_patterns, "api"))),