1
是否有可能在用戶通過AuthenticationForm
的confirm_login_allowed
後重定向。重定向自定義AuthenticationForm一旦通過身份驗證 - Django
例如,我試圖做
class LoginForm(AuthenticationForm):
def confirm_login_allowed(self, user):
if not user.is_active:
raise forms.ValidationError('There was a problem with your login.', code='invalid_login')
elif user.is_staff and not self.has_2fa():
logger.info('is staff but does not have 2FA, redirecting to Authy account creator')
return redirect('admin/authy_me/authenticatormodel/')
elif user.is_staff and self.has_2fa():
logger.info("is staff and 2FA enabled")
elif not user.is_staff and not self.has_2fa():
logger.info('is not staff and does not have 2FA')
只爲驗證錯誤使用
或confirm_login_allowed
在形式將用戶重定向?如果有,還有其他方法嗎?