Ejemplo n.º 1
0
    def form_valid(self, form):
        """ 表单验证通过,返回成功url """
        if not self.request.session.test_cookie_worked():
            return HttpResponse(_('Please enable cookies and try again.'))

        set_tmp_user_to_cache(self.request, form.get_user())
        return redirect(self.get_success_url())
Ejemplo n.º 2
0
    def form_valid(self, form):
        if not self.request.session.test_cookie_worked():
            return HttpResponse(_("Please enable cookies and try again."))
        user = form.get_user()
        # user password expired
        if user.password_has_expired:
            reason = LoginLog.REASON_PASSWORD_EXPIRED
            self.send_auth_signal(success=False, username=user.username, reason=reason)
            return self.render_to_response(self.get_context_data(password_expired=True))

        set_tmp_user_to_cache(self.request, user)
        username = form.cleaned_data.get('username')
        ip = get_request_ip(self.request)
        # 登陆成功,清除缓存计数
        clean_failed_count(username, ip)
        return redirect(self.get_success_url())
Ejemplo n.º 3
0
    def form_valid(self, form):
        if not self.request.session.test_cookie_worked():
            return HttpResponse(_("Please enable cookies and try again."))
        user = form.get_user()
        # user password expired
        if user.password_has_expired:
            reason = LoginLog.REASON_PASSWORD_EXPIRED
            self.send_auth_signal(success=False, username=user.username, reason=reason)
            return self.render_to_response(self.get_context_data(password_expired=True))

        set_tmp_user_to_cache(self.request, user)
        username = form.cleaned_data.get('username')
        ip = get_request_ip(self.request)
        # 登陆成功,清除缓存计数
        clean_failed_count(username, ip)
        return redirect(self.get_success_url())
Ejemplo n.º 4
0
 def get_redirect_url(self, *args, **kwargs):
     try:
         user = self.check_user_auth_if_need()
         self.check_user_mfa_if_need(user)
         self.check_user_login_confirm_if_need(user)
     except errors.CredentialError:
         return self.format_redirect_url(self.login_url)
     except errors.MFARequiredError:
         return self.format_redirect_url(self.login_otp_url)
     except errors.LoginConfirmBaseError:
         return self.format_redirect_url(self.login_confirm_url)
     else:
         # 启用但是没有设置otp, 排除radius
         if user.mfa_enabled_but_not_set():
             # 1,2,mfa_setting & F
             set_tmp_user_to_cache(self.request, user)
             return reverse('users:user-otp-enable-authentication')
         auth_login(self.request, user)
         self.send_auth_signal(success=True, user=user)
         self.clear_auth_mark()
         url = redirect_user_first_login_or_index(self.request,
                                                  self.redirect_field_name)
         return url