You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					41 lines
				
				1.4 KiB
			
		
		
			
		
	
	
					41 lines
				
				1.4 KiB
			| 
											2 years ago
										 | import uuid | ||
| 
											1 year ago
										 | from datetime import timedelta | ||
| 
											2 years ago
										 | from fastapi import APIRouter, Request | ||
| 
											1 year ago
										 | from config.enums import RedisInitKeyConfig | ||
| 
											2 years ago
										 | from module_admin.entity.vo.login_vo import CaptchaCode | ||
| 
											1 year ago
										 | from module_admin.service.captcha_service import CaptchaService | ||
|  | from utils.response_util import ResponseUtil | ||
|  | from utils.log_util import logger | ||
| 
											2 years ago
										 | 
 | ||
|  | 
 | ||
|  | captchaController = APIRouter() | ||
|  | 
 | ||
|  | 
 | ||
| 
											1 year ago
										 | @captchaController.get('/captchaImage') | ||
| 
											2 years ago
										 | async def get_captcha_image(request: Request): | ||
| 
											1 year ago
										 |     captcha_enabled = ( | ||
|  |         True | ||
| 
											1 year ago
										 |         if await request.app.state.redis.get(f'{RedisInitKeyConfig.SYS_CONFIG.key}:sys.account.captchaEnabled') | ||
| 
											1 year ago
										 |         == 'true' | ||
|  |         else False | ||
|  |     ) | ||
|  |     register_enabled = ( | ||
|  |         True | ||
| 
											1 year ago
										 |         if await request.app.state.redis.get(f'{RedisInitKeyConfig.SYS_CONFIG.key}:sys.account.registerUser') == 'true' | ||
| 
											1 year ago
										 |         else False | ||
|  |     ) | ||
| 
											1 year ago
										 |     session_id = str(uuid.uuid4()) | ||
|  |     captcha_result = await CaptchaService.create_captcha_image_service() | ||
|  |     image = captcha_result[0] | ||
|  |     computed_result = captcha_result[1] | ||
| 
											1 year ago
										 |     await request.app.state.redis.set( | ||
| 
											1 year ago
										 |         f'{RedisInitKeyConfig.CAPTCHA_CODES.key}:{session_id}', computed_result, ex=timedelta(minutes=2) | ||
| 
											1 year ago
										 |     ) | ||
| 
											1 year ago
										 |     logger.info(f'编号为{session_id}的会话获取图片验证码成功') | ||
|  | 
 | ||
|  |     return ResponseUtil.success( | ||
| 
											1 year ago
										 |         model_content=CaptchaCode( | ||
|  |             captchaEnabled=captcha_enabled, registerEnabled=register_enabled, img=image, uuid=session_id | ||
|  |         ) | ||
| 
											1 year ago
										 |     ) |