feat: 添加系统配置,更新验证码接口
This commit is contained in:
41
api/login.py
41
api/login.py
@@ -124,19 +124,38 @@ async def register(request: Request, params: RegisterUserParams):
|
||||
|
||||
@loginAPI.get("/captcha", response_class=JSONResponse, response_model=GetCaptchaResponse, summary="获取验证码")
|
||||
async def get_captcha(request: Request):
|
||||
captcha_result = await Captcha.create_captcha("1")
|
||||
session_id = str(uuid.uuid4())
|
||||
captcha = captcha_result[0]
|
||||
result = captcha_result[-1]
|
||||
await request.app.state.redis.set(
|
||||
f'{RedisKeyConfig.CAPTCHA_CODES.key}:{session_id}', result, ex=timedelta(minutes=2)
|
||||
captcha_enabled = (
|
||||
True
|
||||
if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account_captcha_enabled')
|
||||
== 'true'
|
||||
else False
|
||||
)
|
||||
logger.info(f'编号为{session_id}的会话获取图片验证码成功')
|
||||
if captcha_enabled:
|
||||
captcha_type = (
|
||||
await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account_captcha_type')
|
||||
if await request.app.state.redis.get(f'{RedisKeyConfig.SYSTEM_CONFIG.key}:account_captcha_type')
|
||||
else "1"
|
||||
)
|
||||
captcha_result = await Captcha.create_captcha(captcha_type)
|
||||
session_id = str(uuid.uuid4())
|
||||
captcha = captcha_result[0]
|
||||
result = captcha_result[-1]
|
||||
await request.app.state.redis.set(
|
||||
f'{RedisKeyConfig.CAPTCHA_CODES.key}:{session_id}', result, ex=timedelta(minutes=2)
|
||||
)
|
||||
logger.info(f'编号为{session_id}的会话获取图片验证码成功')
|
||||
|
||||
return Response.success(data={
|
||||
"uuid": session_id,
|
||||
"captcha": captcha,
|
||||
})
|
||||
return Response.success(data={
|
||||
"uuid": session_id,
|
||||
"captcha": captcha,
|
||||
"captcha_enabled": captcha_enabled,
|
||||
})
|
||||
else:
|
||||
return Response.success(data={
|
||||
"uuid": None,
|
||||
"captcha": None,
|
||||
"captcha_enabled": captcha_enabled,
|
||||
})
|
||||
|
||||
|
||||
@loginAPI.post("/code", response_class=JSONResponse, response_model=BaseResponse, summary="获取邮件验证码")
|
||||
|
||||
Reference in New Issue
Block a user