mirror of
https://github.com/MOIS3Y/logs-collector.git
synced 2025-09-13 05:03:01 +02:00
Refactoring: using the apps directory is redundant
This commit is contained in:
0
logs_collector/account/__init__.py
Normal file
0
logs_collector/account/__init__.py
Normal file
3
logs_collector/account/admin.py
Normal file
3
logs_collector/account/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
7
logs_collector/account/apps.py
Normal file
7
logs_collector/account/apps.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'account'
|
||||
verbose_name = 'Auth and account management'
|
0
logs_collector/account/migrations/__init__.py
Normal file
0
logs_collector/account/migrations/__init__.py
Normal file
3
logs_collector/account/models.py
Normal file
3
logs_collector/account/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
logs_collector/account/tests.py
Normal file
3
logs_collector/account/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
40
logs_collector/account/urls.py
Normal file
40
logs_collector/account/urls.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from django.conf import settings
|
||||
from django.urls import path
|
||||
from django.contrib.auth.views import LogoutView
|
||||
|
||||
from rest_framework_simplejwt.views import (
|
||||
TokenObtainPairView,
|
||||
TokenRefreshView,
|
||||
TokenVerifyView
|
||||
)
|
||||
|
||||
|
||||
app_name = 'account'
|
||||
|
||||
urlpatterns = [
|
||||
# WEB LOGOUT:
|
||||
path(
|
||||
'account/logout/',
|
||||
LogoutView.as_view(next_page=settings.LOGOUT_REDIRECT_URL),
|
||||
name='logout'
|
||||
)
|
||||
]
|
||||
|
||||
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'
|
||||
),
|
||||
]
|
46
logs_collector/account/utils.py
Normal file
46
logs_collector/account/utils.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||
from django.contrib.auth.views import redirect_to_login
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import resolve_url
|
||||
from django.urls import reverse
|
||||
from django.utils.http import url_has_allowed_host_and_scheme # renamed Dj^3.*
|
||||
from two_factor.admin import AdminSiteOTPRequired, AdminSiteOTPRequiredMixin
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/48600737/django-two-factor-auth-cant-access-admin-site
|
||||
class AdminSiteOTPRequiredMixinRedirectSetup(AdminSiteOTPRequired):
|
||||
"""
|
||||
Fixes the current implementation of django-two-factor-auth = 1.15.3
|
||||
when admin page is patched for 2fa
|
||||
(circular redirect - super user created with manage.py
|
||||
and cannot log in because he does not have a device configured).
|
||||
The class redirects to the setup page.
|
||||
After that, you can log in as usual.
|
||||
"""
|
||||
def login(self, request, extra_context=None):
|
||||
redirect_to = request.POST.get(
|
||||
REDIRECT_FIELD_NAME, request.GET.get(REDIRECT_FIELD_NAME)
|
||||
)
|
||||
# For users not yet verified the AdminSiteOTPRequired.has_permission
|
||||
# will fail. So use the standard admin has_permission check:
|
||||
# (is_active and is_staff) and then check for verification.
|
||||
# Go to index if they pass, otherwise make them setup OTP device.
|
||||
if request.method == "GET" and super(
|
||||
AdminSiteOTPRequiredMixin, self
|
||||
).has_permission(request):
|
||||
# Already logged-in and verified by OTP
|
||||
if request.user.is_verified():
|
||||
# User has permission
|
||||
index_path = reverse("admin:index", current_app=self.name)
|
||||
else:
|
||||
# User has permission but no OTP set:
|
||||
index_path = reverse("two_factor:setup", current_app=self.name)
|
||||
return HttpResponseRedirect(index_path)
|
||||
|
||||
if not redirect_to or not url_has_allowed_host_and_scheme(
|
||||
url=redirect_to, allowed_hosts=[request.get_host()]
|
||||
):
|
||||
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
|
||||
|
||||
return redirect_to_login(redirect_to)
|
0
logs_collector/account/views.py
Normal file
0
logs_collector/account/views.py
Normal file
Reference in New Issue
Block a user