Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /mdfarhankc_fastapi-fullauth /fastapi_fullauth /flows /register.py
| import logging | |
| from typing import Literal | |
| from fastapi_fullauth.adapters.base import AbstractUserAdapter | |
| from fastapi_fullauth.core.crypto import ahash_password | |
| from fastapi_fullauth.exceptions import UserAlreadyExistsError | |
| from fastapi_fullauth.types import CreateUserSchema, UserSchema | |
| from fastapi_fullauth.validators import PasswordValidator | |
| logger = logging.getLogger("fastapi_fullauth.register") | |
| async def register( | |
| adapter: AbstractUserAdapter, | |
| data: CreateUserSchema, | |
| login_field: str = "email", | |
| hash_algorithm: Literal["argon2id", "bcrypt"] = "argon2id", | |
| password_validator: PasswordValidator | None = None, | |
| ) -> UserSchema: | |
| if password_validator: | |
| password_validator.validate(data.password) | |
| existing = await adapter.get_user_by_email(data.email) | |
| if existing is not None: | |
| logger.warning("Registration rejected; email exists: %s", data.email) | |
| raise UserAlreadyExistsError(f"User with email {data.email} already exists") | |
| if login_field != "email": | |
| login_value = getattr(data, login_field, None) | |
| if login_value is not None: | |
| existing = await adapter.get_user_by_field(login_field, login_value) | |
| if existing is not None: | |
| logger.warning("Registration rejected = %s exists", login_field) | |
| raise UserAlreadyExistsError(f"User with {login_field} already exists") | |
| hashed = await ahash_password(data.password, algorithm=hash_algorithm) | |
| user = await adapter.create_user(data, hashed_password=hashed) | |
| logger.info("User registered: user_id=%s, email=%s", user.id, user.email) | |
| return user | |
Xet Storage Details
- Size:
- 1.64 kB
- Xet hash:
- 0b2b4584c7ee2dfbbf02c6ee9939f1529236f6167002be75655cb9564e9e20ec
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.