perf: 同步近期修改

This commit is contained in:
2025-02-21 02:38:30 +08:00
parent d5e0f9d5ac
commit 003e7b8742
8 changed files with 162 additions and 23 deletions

View File

@@ -38,6 +38,8 @@ async def login(
request: Request,
params: CustomOAuth2PasswordRequestForm = Depends()
):
request.app.state.session_id = None
request.app.state.login_status = False
user = LoginParams(
username=params.username,
password=params.password,
@@ -47,7 +49,7 @@ async def login(
)
captcha_enabled = (
True
if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account.captcha_enabled')
if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account_captcha_enabled')
== 'true'
else False
)
@@ -75,6 +77,7 @@ async def login(
ex=timedelta(minutes=5),
)
request.app.state.session_id = result["session_id"]
request.app.state.login_status = True
if request_from_swagger or request_from_redoc:
return {'access_token': result["accessToken"], 'token_type': 'Bearer',
"expires_in": result["expiresIn"] * 60}
@@ -83,6 +86,7 @@ async def login(
result.pop("session_id")
result.pop("userInfo")
return Response.success(data=result)
request.app.state.login_status = False
return Response.failure(msg="登录失败,账号或密码错误!")
@@ -90,7 +94,7 @@ async def login(
async def register(request: Request, params: RegisterUserParams):
register_enabled = (
True
if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account_register_enabled')
if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:register_enabled')
== 'true'
else False
)