fix(auth): handle scenario where the user is null

This commit is contained in:
InfinityPacer
2024-09-16 15:41:13 +08:00
parent 4efc80e35a
commit 36142b97bf
+7 -3
View File
@@ -38,9 +38,13 @@ async def login_access_token(
otp_password=otp_password otp_password=otp_password
) )
if not success: if not success:
# 认证不成功且开启了辅助认证 # 认证不成功
if not user and settings.AUXILIARY_AUTH_ENABLE: if not user:
# 未找到用户,请求协助认证 if not settings.AUXILIARY_AUTH_ENABLE:
logger.warn(f"用户 {form_data.username} 登录失败!")
raise HTTPException(status_code=401, detail="用户名、密码或二次校验码不正确")
else:
# 如果找不到用户并开启了辅助认证
logger.warn(f"登录用户 {form_data.username} 本地不存在,尝试辅助认证 ...") logger.warn(f"登录用户 {form_data.username} 本地不存在,尝试辅助认证 ...")
token = UserChain().user_authenticate(form_data.username, form_data.password) token = UserChain().user_authenticate(form_data.username, form_data.password)
if not token: if not token: