infrastructure.persistence.repositories.email_verification_token_repository¶
src.infrastructure.persistence.repositories.email_verification_token_repository
¶
EmailVerificationTokenRepository - SQLAlchemy implementation for email verification token persistence.
Handles CRUD operations for email verification tokens with expiration checks.
Classes¶
EmailVerificationTokenRepository
¶
SQLAlchemy implementation for email verification token persistence.
Manages email verification tokens with support for: - Token creation and storage - Token validation (lookup by token string) - One-time use enforcement (mark as used)
Attributes:
| Name | Type | Description |
|---|---|---|
session |
SQLAlchemy async session for database operations. |
Example
async with get_session() as session: ... repo = EmailVerificationTokenRepository(session) ... token = await repo.find_by_token("abc123...")
Source code in src/infrastructure/persistence/repositories/email_verification_token_repository.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Functions¶
__init__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AsyncSession
|
SQLAlchemy async session. |
required |
save
async
¶
Create new email verification token in database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
UUID
|
User's unique identifier. |
required |
token
|
str
|
Random hex token (64 characters). |
required |
expires_at
|
datetime
|
Token expiration timestamp (24 hours). |
required |
Returns:
| Type | Description |
|---|---|
EmailVerificationTokenData
|
Created EmailVerificationTokenData. |
Source code in src/infrastructure/persistence/repositories/email_verification_token_repository.py
find_by_token
async
¶
Find email verification token by token string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
The verification token string. |
required |
Returns:
| Type | Description |
|---|---|
EmailVerificationTokenData | None
|
EmailVerificationTokenData if found and not used, None otherwise. |
Source code in src/infrastructure/persistence/repositories/email_verification_token_repository.py
mark_as_used
async
¶
Mark email verification token as used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_id
|
UUID
|
Token's unique identifier. |
required |
Source code in src/infrastructure/persistence/repositories/email_verification_token_repository.py
delete_expired_tokens
async
¶
Delete expired email verification tokens.
Cleanup task to remove old tokens (typically run daily).
Returns:
| Type | Description |
|---|---|
int
|
Number of tokens deleted. |
Source code in src/infrastructure/persistence/repositories/email_verification_token_repository.py
find_by_user_id
async
¶
Find all email verification tokens for a user.
Useful for debugging or admin views.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
UUID
|
User's unique identifier. |
required |
Returns:
| Type | Description |
|---|---|
list[EmailVerificationTokenData]
|
List of EmailVerificationTokenData. |