Account¶
account
¶
Account management core logic.
Provides business logic for account operations including password change, email change, and account deletion.
Classes¶
InvalidPasswordError
¶
Bases: Exception
Raised when the current password is incorrect.
UserNotFoundError
¶
Bases: Exception
Raised when the user is not found.
EmailChangeError
¶
Bases: Exception
Raised when there's an error with email change.
EmailAlreadyExistsError
¶
Bases: Exception
Raised when the new email already exists.
Functions¶
change_password
¶
change_password(
*,
users: UserAdapter,
sessions: SessionAdapter,
user_id: UUID,
current_password: str,
new_password: str,
current_session_id: UUID | None = None
) -> None
Change a user's password.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
users |
UserAdapter
|
User adapter for database operations |
required |
sessions |
SessionAdapter
|
Session adapter for database operations |
required |
user_id |
UUID
|
ID of the user changing their password |
required |
current_password |
str
|
Current password for verification |
required |
new_password |
str
|
New password to set |
required |
current_session_id |
UUID | None
|
Optional session ID to preserve during logout |
None
|
Raises:
| Type | Description |
|---|---|
UserNotFoundError
|
If the user doesn't exist |
InvalidPasswordError
|
If the current password is incorrect |
Source code in fastauth/core/account.py
request_email_change
¶
request_email_change(
*,
users: UserAdapter,
email_changes: EmailChangeAdapter,
user_id: UUID,
new_email: str,
expires_in_minutes: int | None = None
) -> str | None
Request an email change for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
users |
UserAdapter
|
User adapter for database operations |
required |
email_changes |
EmailChangeAdapter
|
Email change adapter for database operations |
required |
user_id |
UUID
|
ID of the user requesting email change |
required |
new_email |
str
|
New email address |
required |
expires_in_minutes |
int | None
|
Token expiration time in minutes (defaults to settings value) |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Verification token if successful, None if user not found |
Raises:
| Type | Description |
|---|---|
EmailAlreadyExistsError
|
If the new email already exists |
Source code in fastauth/core/account.py
confirm_email_change
¶
confirm_email_change(
*, users: UserAdapter, email_changes: EmailChangeAdapter, token: str
) -> None
Confirm an email change with a verification token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
users |
UserAdapter
|
User adapter for database operations |
required |
email_changes |
EmailChangeAdapter
|
Email change adapter for database operations |
required |
token |
str
|
Verification token |
required |
Raises:
| Type | Description |
|---|---|
EmailChangeError
|
If token is invalid or expired |
EmailAlreadyExistsError
|
If the new email already exists |
Source code in fastauth/core/account.py
delete_account
¶
delete_account(
*,
users: UserAdapter,
sessions: SessionAdapter,
user_id: UUID,
password: str,
hard_delete: bool = False
) -> None
Delete a user account (soft or hard delete).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
users |
UserAdapter
|
User adapter for database operations |
required |
sessions |
SessionAdapter
|
Session adapter for database operations |
required |
user_id |
UUID
|
ID of the user to delete |
required |
password |
str
|
Password for verification |
required |
hard_delete |
bool
|
If True, permanently delete the user; if False, soft delete |
False
|
Raises:
| Type | Description |
|---|---|
UserNotFoundError
|
If the user doesn't exist |
InvalidPasswordError
|
If the password is incorrect |