25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
from django.shortcuts import redirect
|
|
from django.urls import reverse
|
|
from B_main.models import Person
|
|
|
|
class ForcePasswordSetMiddleware:
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
# 로그인한 사용자이고 비밀번호 설정이 필요한 경우
|
|
if request.user.is_authenticated:
|
|
try:
|
|
person = Person.objects.get(user=request.user)
|
|
if person.비밀번호설정필요:
|
|
# 현재 URL이 강제 비밀번호 설정 페이지가 아닌 경우에만 리다이렉트
|
|
current_path = request.path
|
|
force_password_set_path = reverse('accounts:force_password_set')
|
|
|
|
if current_path != force_password_set_path and not current_path.startswith('/admin/'):
|
|
return redirect('accounts:force_password_set')
|
|
except Person.DoesNotExist:
|
|
pass
|
|
|
|
response = self.get_response(request)
|
|
return response |