perf: 优化OIDC用户未激活时,会循环跳转登录页面

This commit is contained in:
jiangweidong
2023-10-09 17:55:44 +08:00
committed by Bryan
parent 3d27986c96
commit 3ac35eec68
5 changed files with 110 additions and 98 deletions

View File

@@ -166,7 +166,7 @@ class OIDCAuthCallbackView(View):
code_verifier = request.session.get('oidc_auth_code_verifier', None)
logger.debug(log_prompt.format('Process authenticate'))
user = auth.authenticate(nonce=nonce, request=request, code_verifier=code_verifier)
if user and user.is_valid:
if user:
logger.debug(log_prompt.format('Login: {}'.format(user)))
auth.login(self.request, user)
# Stores an expiration timestamp in the user's session. This value will be used if

View File

@@ -92,7 +92,7 @@ class ThirdPartyLoginMiddleware(mixins.AuthMixin):
'title': _('Authentication failed'),
'message': _('Authentication failed (before login check failed): {}').format(e),
'interval': 10,
'redirect_url': reverse('authentication:login'),
'redirect_url': reverse('authentication:login') + '?admin=0',
'auto_redirect': True,
}
response = render(request, 'authentication/auth_fail_flash_message_standalone.html', context)

View File

@@ -76,6 +76,12 @@ def authenticate(request=None, **credentials):
if user is None:
continue
if not user.is_valid:
temp_user = user
temp_user.backend = backend_path
request.error_message = _('User is not valid')
return temp_user
# 检查用户是否允许认证
if not backend.user_allow_authenticate(user):
temp_user = user