From bc147b96172da048b9fa04eea58b9c57b984ae25 Mon Sep 17 00:00:00 2001 From: CodeWizardette Date: Fri, 18 Aug 2023 12:26:26 +0300 Subject: [PATCH] main --- envanter/envanter/authentication.py | 13 ++++++ envanter/envanter/settings.py | 1 + envanter/envanter/teplates/index.html | 65 +++++++-------------------- envanter/envanter/urls.py | 1 - envanter/envanter/views.py | 5 +++ 5 files changed, 35 insertions(+), 50 deletions(-) create mode 100644 envanter/envanter/authentication.py diff --git a/envanter/envanter/authentication.py b/envanter/envanter/authentication.py new file mode 100644 index 0000000..bf8d31b --- /dev/null +++ b/envanter/envanter/authentication.py @@ -0,0 +1,13 @@ +from django.shortcuts import redirect +from django.urls import reverse + +class LoginRequiredMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + if not request.user.is_authenticated and request.path != reverse('login'): + return redirect('login') # Kullanıcı giriş yapmamışsa ve giriş yapma sayfasına yönlendirilir. + + response = self.get_response(request) + return response diff --git a/envanter/envanter/settings.py b/envanter/envanter/settings.py index 9b517e2..efa9277 100644 --- a/envanter/envanter/settings.py +++ b/envanter/envanter/settings.py @@ -42,6 +42,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'envanter.middlewares.authentication.LoginRequiredMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/envanter/envanter/teplates/index.html b/envanter/envanter/teplates/index.html index 6858c77..8dc4c91 100644 --- a/envanter/envanter/teplates/index.html +++ b/envanter/envanter/teplates/index.html @@ -6,6 +6,11 @@ envo