Files
timerr/apps/accounts/middleware.py
T
2026-07-15 00:12:31 +05:00

15 lines
524 B
Python

from django.shortcuts import redirect
from django.urls import reverse
class PasswordChangeRequiredMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if request.user.is_authenticated and request.user.must_change_password:
allowed_paths = {reverse("logout"), reverse("password-change")}
if request.path not in allowed_paths:
return redirect("password-change")
return self.get_response(request)