Draft: Two factor auth #118
5 changed files with 42 additions and 9 deletions
|
|
@ -7,9 +7,7 @@
|
||||||
|
|
||||||
{% block intro %}
|
{% block intro %}
|
||||||
<div class="form__intro">
|
<div class="form__intro">
|
||||||
{% if wizard.steps.current == 'auth' %}
|
{% if wizard.steps.current == 'token' %}
|
||||||
<p>{% blocktrans %}Enter your credentials.{% endblocktrans %}</p>
|
|
||||||
{% elif wizard.steps.current == 'token' %}
|
|
||||||
{% if device.method == 'call' %}
|
{% if device.method == 'call' %}
|
||||||
<p>
|
<p>
|
||||||
{% blocktrans trimmed %}
|
{% blocktrans trimmed %}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,18 @@
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.urls import include, path
|
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 (
|
from newsreader.accounts.views import (
|
||||||
ActivationCompleteView,
|
ActivationCompleteView,
|
||||||
ActivationResendView,
|
ActivationResendView,
|
||||||
|
|
@ -67,8 +79,28 @@ settings_patterns = [
|
||||||
path("", login_required(SettingsView.as_view()), name="home"),
|
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/<int:pk>/",
|
||||||
|
PhoneDeleteView.as_view(),
|
||||||
|
name="phone_delete",
|
||||||
|
),
|
||||||
|
path("accounts/profile/", ProfileView.as_view(), name="profile"),
|
||||||
|
path("accounts/disable/", DisableView.as_view(), name="disable"),
|
||||||
|
]
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Auth
|
# Auth
|
||||||
|
path("", include((two_factor, "two_factor"))),
|
||||||
path("login/", LoginView.as_view(), name="login"),
|
path("login/", LoginView.as_view(), name="login"),
|
||||||
path("logout/", LogoutView.as_view(), name="logout"),
|
path("logout/", LogoutView.as_view(), name="logout"),
|
||||||
# Register
|
# Register
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
from django.contrib.auth import views as django_views
|
from django.contrib.auth import views as django_views
|
||||||
from django.urls import reverse_lazy
|
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"
|
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):
|
class LogoutView(django_views.LogoutView):
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Authentication user model
|
# Authentication user model
|
||||||
AUTH_USER_MODEL = "accounts.User"
|
AUTH_USER_MODEL = "accounts.User"
|
||||||
|
|
||||||
LOGIN_URL = "two_factor:login"
|
LOGIN_URL = "accounts:login"
|
||||||
LOGIN_REDIRECT_URL = "/"
|
LOGIN_REDIRECT_URL = "/"
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
|
|
@ -259,6 +259,7 @@ SWAGGER_SETTINGS = {
|
||||||
# https://docs.celeryproject.org/en/stable/userguide/configuration.html
|
# https://docs.celeryproject.org/en/stable/userguide/configuration.html
|
||||||
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
|
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
|
||||||
|
|
||||||
|
# Registration
|
||||||
REGISTRATION_OPEN = True
|
REGISTRATION_OPEN = True
|
||||||
REGISTRATION_AUTO_LOGIN = True
|
REGISTRATION_AUTO_LOGIN = True
|
||||||
ACCOUNT_ACTIVATION_DAYS = 7
|
ACCOUNT_ACTIVATION_DAYS = 7
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from django.urls import include, path
|
||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
from drf_yasg.views import get_schema_view
|
from drf_yasg.views import get_schema_view
|
||||||
from two_factor.admin import AdminSiteOTPRequired
|
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.accounts.urls import urlpatterns as login_urls
|
||||||
from newsreader.news.core.views import NewsView
|
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
|
admin.site.__class__ = AdminSiteOTPRequired
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include(two_factor_urls)),
|
|
||||||
path("", login_required(NewsView.as_view()), name="index"),
|
path("", login_required(NewsView.as_view()), name="index"),
|
||||||
path("", include((news_patterns, "news"))),
|
path("", include((news_patterns, "news"))),
|
||||||
path("", include((api_patterns, "api"))),
|
path("", include((api_patterns, "api"))),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue