- commit
- 8e1d7ef41076370e65739871368699c311c6582a
- parent
- 43aac7d1de4c3fa27673a6fb1fc50306385296a0
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-04-06 13:25
add ForceLoginMiddleware
Diffstat
| A | utils/force_auth.py | 16 | ++++++++++++++++ |
1 files changed, 16 insertions, 0 deletions
diff --git a/utils/force_auth.py b/utils/force_auth.py
@@ -0,0 +1,16 @@ -1 1 from django.conf import settings -1 2 from django.contrib.auth import REDIRECT_FIELD_NAME -1 3 from django.contrib.auth.views import redirect_to_login -1 4 from django.utils.deprecation import MiddlewareMixin -1 5 -1 6 -1 7 class ForceLoginMiddleware(MiddlewareMixin): -1 8 def process_request(self, request): -1 9 if request.path in settings.FORCE_LOGIN_IGNORE: -1 10 return -1 11 if not request.user.is_authenticated: -1 12 return redirect_to_login( -1 13 self.request.get_full_path(), -1 14 settings.LOGIN_URL, -1 15 REDIRECT_FIELD_NAME, -1 16 )