Create: MVP 2fa account app

This commit is contained in:
2023-08-14 16:56:17 +09:00
parent 2e648ac4fe
commit 30b3efa5fc
37 changed files with 882 additions and 134 deletions

View File

@@ -36,12 +36,18 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'collector.apps.CollectorConfig', # main app
'account.apps.AccountConfig', # account app
'rest_framework',
'rest_framework_simplejwt',
'django_filters',
'drf_spectacular',
"crispy_forms",
"crispy_bootstrap5",
'django_otp',
'django_otp.plugins.otp_static',
'django_otp.plugins.otp_totp',
'two_factor.plugins.phonenumber', # <- if you want phone number capability
'two_factor',
'django_cleanup.apps.CleanupConfig', # required bottom
]
@@ -51,6 +57,7 @@ MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_otp.middleware.OTPMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
@@ -60,7 +67,7 @@ ROOT_URLCONF = 'logs_collector.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@@ -216,3 +223,7 @@ SIMPLE_JWT = {
"SLIDING_TOKEN_OBTAIN_SERIALIZER": "rest_framework_simplejwt.serializers.TokenObtainSlidingSerializer", # noqa:E501
"SLIDING_TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSlidingSerializer", # noqa:E501
}
LOGIN_URL = 'two_factor:login'
LOGIN_REDIRECT_URL = 'collector:index'
LOGOUT_REDIRECT_URL = 'two_factor:login'

View File

@@ -1,60 +1,28 @@
"""
URL configuration for logs_collector project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView
)
from drf_spectacular.views import (
SpectacularAPIView,
SpectacularRedocView,
SpectacularSwaggerView
)
from two_factor.urls import urlpatterns as tf_urls
from logs_collector import settings
from account.utils import AdminSiteOTPRequiredMixinRedirectSetup
# ? 2FA patch (Admin site protection)
admin.site.__class__ = AdminSiteOTPRequiredMixinRedirectSetup
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('collector.urls', namespace='collector')),
]
urlpatterns += [
# JWT AUTH:
path(
'api/v1/auth/token/',
TokenObtainPairView.as_view(),
name='token_obtain_pair'
),
path(
'api/v1/auth/token/refresh/',
TokenRefreshView.as_view(),
name='token_refresh'
),
path(
'api/v1/auth/token/verify/',
TokenVerifyView.as_view(),
name='token_verify'
),
path('', include(tf_urls)),
path('', include('account.urls', namespace='account'))
]
urlpatterns += [