1. 사용자가 로그인 성공 후 후속 프로세스가 필요할 때 처리방법. (여기서는 superuser가 로그인하면 session 정보 삭제 처리)

2. /BlogVenv/Lib/site-packages/django/contrib/auth/views.py

...
# 추가
from userSession.views import UserSessionAV
...


class LoginView(SuccessURLAllowedHostsMixin, FormView):
...

    def form_valid(self, form):
        """Security check complete. Log the user in."""
        auth_login(self.request, form.get_user())
        
        # Processing after loggined
        UserSessionAV.delete(self.request)    # 추가
        
        return HttpResponseRedirect(self.get_success_url())
...

 

3. /userSession/views.py

 ...

    @classmethod
    def delete(cls, request):
        
        # IF Loggined User is superuser, Remove Access & Trace Info.
        if request.user.is_superuser:
            _ses_id = request.COOKIES.get(settings.COOKIE_SES_ID)
            
            if _ses_id:
                try:
                    UserSession.objects.get(ses_id=_ses_id).delete()
                    
                except UserSession.DoesNotExist as e:
                    pass

...

 

※ 참고
인증성공시 LoginView Class의 Method 호출 순서

dispatch
get_context_data    <- 인증화면열때만 호출
get_form_class
get_form_kwargs
form_valid
get_success_url
get_redirect_url