Autologin
Some checks are pending
Docker hub build / docker (push) Waiting to run

This commit is contained in:
A B
2024-10-28 00:06:35 +00:00
parent b6ad6e8578
commit 7cf99af20d
5 changed files with 33 additions and 18 deletions

View File

@@ -1,6 +1,5 @@
from django.urls import resolve
from django.http import Http404, HttpResponseNotFound
from django.contrib.auth.middleware import RemoteUserMiddleware
from django.contrib.auth import authenticate, login
from django.utils.deprecation import MiddlewareMixin
class RequestLogger:
def __init__(self, get_response):
@@ -15,5 +14,9 @@ class RequestLogger:
return response
class AutoLoginMiddleware(RemoteUserMiddleware):
header = "HTTP_X_AUTHENTIK_USERNAME"
class AutoLoginMiddleware(MiddlewareMixin):
def process_request(self, request):
if not request.user.is_authenticated:
user = authenticate(username='admin', password='admin')
if user:
login(request, user)

View File

@@ -3,6 +3,7 @@ import os
import environ
from django.core.management.utils import get_random_secret_key
ENV = environ.Env(
DEBUG=(bool, False)
)
@@ -23,13 +24,6 @@ CELERY_RESULT_EXTENDED = True
AUTH_USER_MODEL = "vpn.User"
# CACHES = {
# 'default': {
# 'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
# 'LOCATION': 'cache_table',
# }
# }
DEBUG = ENV('DEBUG')
ALLOWED_HOSTS = ENV.list('ALLOWED_HOSTS', default=["*"])
@@ -109,10 +103,6 @@ INSTALLED_APPS = [
'vpn',
]
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.RemoteUserBackend",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
@@ -120,7 +110,6 @@ MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'mysite.middleware.AutoLoginMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',