leaguemanager.services.account.user

Module Contents

Classes

UserSyncService

Handles user database operations.

UserAsyncService

Handles user database operations.

Data

__all__

settings

MAX_FAILED_RESET_ATTEMPTS

API

leaguemanager.services.account.user.__all__

[‘UserSyncService’, ‘UserAsyncService’]

leaguemanager.services.account.user.settings

‘get_settings(…)’

leaguemanager.services.account.user.MAX_FAILED_RESET_ATTEMPTS

5

class leaguemanager.services.account.user.UserSyncService

Bases: leaguemanager.services.base.SQLAlchemySyncRepositoryService

Handles user database operations.

class Repo

Bases: advanced_alchemy.repository.SQLAlchemySyncRepository[leaguemanager.models.User]

User repository.

model_type

None

repository_type

None

class leaguemanager.services.account.user.UserAsyncService

Bases: leaguemanager.services.base.SQLAlchemyAsyncRepositoryService

Handles user database operations.

class Repo

Bases: advanced_alchemy.repository.SQLAlchemyAsyncRepository[leaguemanager.models.User]

User repository.

model_type

None

default_role

None

match_fields

[‘email’]

repository_type

None

async authenticate(username: str, password: bytes | str) leaguemanager.models.User

Authenticate a user against the stored hashed password.

Returns: The user object if authentication is successful.

Raises: PermissionDenied: If fails to locate, password is incorrect, or user inactive.

async verify_email(user_id: uuid.UUID, email: str) leaguemanager.models.User

Verify a user’s email. Generally used for web app usage.

Args: user_id (UUID): The ID of the user. email (str): The email to verify.

Returns: m.User: The updated user object with verified email.

async require_verified_email(user: leaguemanager.models.User) None

Ensure the user has a verified email.

Args: user (m.User): The user object to check.

Raises: HTTPException: If the user’s email is not verified.

async update_password(data: dict[str | Any], user: leaguemanager.models.User) leaguemanager.models.User

Update the user’s password.

Args: data (dict): The data containing the new password. user (m.User): The user object to update.

Returns: m.User: The updated user object with the new password.

async static has_role_id(db_obj: leaguemanager.models.User, role_id: uuid.UUID) bool

Return true if user has specified role ID

async static has_role(db_obj: leaguemanager.models.User, role_name: str) bool

Return true if user has specified role ID

static is_superuser(user: leaguemanager.models.User) bool
async reset_password_with_token(user_id: uuid.UUID, new_password: str) leaguemanager.models.User

Reset user’s password using a validated token.

Args: user_id: The user’s UUID new_password: The new password

Returns: The updated user object

Raises: HTTPException: If user not found or password validation fails

async increment_failed_reset_attempt(user_id: uuid.UUID) None

Increment failed reset attempts counter.

Args: user_id: The user’s UUID

async create_user_from_oauth(oauth_data: dict[str, Any], provider: str, token_data: httpx_oauth.oauth2.OAuth2Token) leaguemanager.models.User

Create new user from OAuth data.

Args: oauth_data: User data from OAuth provider provider: OAuth provider name (e.g., ‘google’) token_data: OAuth token data

Returns: The created user object

async authenticate_or_create_oauth_user(provider: str, oauth_data: dict[str, Any], token_data: httpx_oauth.oauth2.OAuth2Token) tuple[leaguemanager.models.User, bool]

Authenticate existing OAuth user or create new one.

Args: provider: OAuth provider name oauth_data: User data from OAuth provider token_data: OAuth token data

Returns: Tuple of (user, is_new_user)