Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /fastapi-users_fastapi-users /fastapi_users /router /register.py
| from fastapi import APIRouter, Depends, HTTPException, Request, status | |
| from fastapi_users import exceptions, models, schemas | |
| from fastapi_users.manager import BaseUserManager, UserManagerDependency | |
| from fastapi_users.router.common import ErrorCode, ErrorModel | |
| def get_register_router( | |
| get_user_manager: UserManagerDependency[models.UP, models.ID], | |
| user_schema: type[schemas.U], | |
| user_create_schema: type[schemas.UC], | |
| ) -> APIRouter: | |
| """Generate a router with the register route.""" | |
| router = APIRouter() | |
| async def register( | |
| request: Request, | |
| user_create: user_create_schema, # type: ignore | |
| user_manager: BaseUserManager[models.UP, models.ID] = Depends(get_user_manager), | |
| ): | |
| try: | |
| created_user = await user_manager.create( | |
| user_create, safe=True, request=request | |
| ) | |
| except exceptions.UserAlreadyExists: | |
| raise HTTPException( | |
| status_code=status.HTTP_400_BAD_REQUEST, | |
| detail=ErrorCode.REGISTER_USER_ALREADY_EXISTS, | |
| ) | |
| except exceptions.InvalidPasswordException as e: | |
| raise HTTPException( | |
| status_code=status.HTTP_400_BAD_REQUEST, | |
| detail={ | |
| "code": ErrorCode.REGISTER_INVALID_PASSWORD, | |
| "reason": e.reason, | |
| }, | |
| ) | |
| return user_schema.model_validate(created_user) | |
| return router | |
Xet Storage Details
- Size:
- 2.83 kB
- Xet hash:
- 778f4816824e3a1557aaa39656a2e9a3d42cf4f5f324f2d9e0cf5b2dcd6943df
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.