application.commands.handlers.verify_email_handler¶
src.application.commands.handlers.verify_email_handler
¶
Email verification handler for User Authentication.
Flow: 1. Emit EmailVerificationAttempted event 2. Find token by token string 3. Check token exists 4. Check token not expired 5. Check token not already used 6. Update user.is_verified = True 7. Mark token as used 8. Emit EmailVerificationSucceeded event 9. Return Success(user_id)
On failure: - Emit EmailVerificationFailed event - Return Failure(error)
Architecture: - Application layer ONLY imports from domain layer (entities, protocols, events) - NO infrastructure imports (repositories are injected via protocols) - Handler orchestrates business logic without knowing persistence details
Classes¶
VerifyEmailError
¶
Email verification error reasons.
Source code in src/application/commands/handlers/verify_email_handler.py
VerifyEmailHandler
¶
Handler for email verification command.
Follows hexagonal architecture: - Application layer (this handler) - Domain layer (User entity, protocols) - Infrastructure layer (repositories via dependency injection)
Source code in src/application/commands/handlers/verify_email_handler.py
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
Functions¶
__init__
¶
__init__(
user_repo: UserRepository,
verification_token_repo: EmailVerificationTokenRepository,
event_bus: EventBusProtocol,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_repo
|
UserRepository
|
User repository for persistence. |
required |
verification_token_repo
|
EmailVerificationTokenRepository
|
Email verification token repository. |
required |
event_bus
|
EventBusProtocol
|
Event bus for publishing domain events. |
required |
Source code in src/application/commands/handlers/verify_email_handler.py
handle
async
¶
Handle email verification command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
VerifyEmail
|
VerifyEmail command (token validated by Annotated types). |
required |
request
|
Request | None
|
Optional FastAPI Request for IP/user agent tracking (PCI-DSS 10.2.7). |
None
|
Returns:
| Type | Description |
|---|---|
Result[UUID, str]
|
Success(user_id) on successful verification. |
Result[UUID, str]
|
Failure(error_message) on failure. |
Side Effects
- Publishes EmailVerificationAttempted event (always).
- Publishes EmailVerificationSucceeded event (on success).
- Publishes EmailVerificationFailed event (on failure).
- Updates User.is_verified to True.
- Marks token as used.
Source code in src/application/commands/handlers/verify_email_handler.py
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |