Browse Source

perf: 优化验证码模块异常处理

master
insistence 7 months ago
parent
commit
95b0cdebfb
  1. 29
      ruoyi-fastapi-backend/module_admin/controller/captcha_controller.py

29
ruoyi-fastapi-backend/module_admin/controller/captcha_controller.py

@ -13,19 +13,16 @@ captchaController = APIRouter()
@captchaController.get("/captchaImage") @captchaController.get("/captchaImage")
async def get_captcha_image(request: Request): async def get_captcha_image(request: Request):
try: captcha_enabled = True if await request.app.state.redis.get(f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.account.captchaEnabled") == 'true' else False
captcha_enabled = True if await request.app.state.redis.get(f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.account.captchaEnabled") == 'true' else False register_enabled = True if await request.app.state.redis.get(
register_enabled = True if await request.app.state.redis.get( f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.account.registerUser") == 'true' else False
f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.account.registerUser") == 'true' else False session_id = str(uuid.uuid4())
session_id = str(uuid.uuid4()) captcha_result = await CaptchaService.create_captcha_image_service()
captcha_result = await CaptchaService.create_captcha_image_service() image = captcha_result[0]
image = captcha_result[0] computed_result = captcha_result[1]
computed_result = captcha_result[1] await request.app.state.redis.set(f"{RedisInitKeyConfig.CAPTCHA_CODES.get('key')}:{session_id}", computed_result, ex=timedelta(minutes=2))
await request.app.state.redis.set(f"{RedisInitKeyConfig.CAPTCHA_CODES.get('key')}:{session_id}", computed_result, ex=timedelta(minutes=2)) logger.info(f'编号为{session_id}的会话获取图片验证码成功')
logger.info(f'编号为{session_id}的会话获取图片验证码成功')
return ResponseUtil.success( return ResponseUtil.success(
model_content=CaptchaCode(captchaEnabled=captcha_enabled, registerEnabled=register_enabled, img=image, uuid=session_id) model_content=CaptchaCode(captchaEnabled=captcha_enabled, registerEnabled=register_enabled, img=image, uuid=session_id)
) )
except Exception as e:
logger.exception(e)
return ResponseUtil.error(msg=str(e))

Loading…
Cancel
Save