mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 05:02:49 +00:00
Update request state usage to context variable (#853)
* Update request state usage to context variable * Update context to custom ctx * Fix the exception interception in opera log * restore elapsed
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Request
|
||||
|
||||
from backend.common.context import ctx
|
||||
from backend.common.response.response_schema import ResponseModel, response_base
|
||||
from backend.common.security.jwt import DependsJwtAuth
|
||||
from backend.core.conf import settings
|
||||
@@ -21,7 +22,7 @@ async def send_email_captcha(
|
||||
recipients: Annotated[str | list[str], Body(embed=True, description='邮件接收者')],
|
||||
) -> ResponseModel:
|
||||
code = ''.join([str(random.randint(1, 9)) for _ in range(6)])
|
||||
ip = request.state.ip
|
||||
ip = ctx.ip
|
||||
await redis_client.set(
|
||||
f'{settings.EMAIL_CAPTCHA_REDIS_PREFIX}:{ip}',
|
||||
code,
|
||||
|
||||
Reference in New Issue
Block a user