|
1 | 1 | import logging |
2 | 2 | from datetime import UTC, datetime, timedelta |
3 | | -from typing import Literal |
4 | 3 |
|
5 | 4 | from aiohttp import web |
6 | 5 | from aiohttp.web import RouteTableDef |
7 | 6 | from common_library.error_codes import create_error_code |
8 | | -from models_library.emails import LowerCaseEmailStr |
9 | | -from pydantic import ( |
10 | | - BaseModel, |
11 | | - ConfigDict, |
12 | | - Field, |
13 | | - PositiveInt, |
14 | | - SecretStr, |
15 | | - field_validator, |
16 | | -) |
17 | 7 | from servicelib.aiohttp import status |
18 | 8 | from servicelib.aiohttp.requests_validation import parse_request_body_as |
19 | 9 | from servicelib.logging_errors import create_troubleshootting_log_kwargs |
|
30 | 20 | session_access_required, |
31 | 21 | ) |
32 | 22 | from ....utils import MINUTE |
33 | | -from ....utils_aiohttp import NextPage, envelope_json_response |
| 23 | +from ....utils_aiohttp import envelope_json_response |
34 | 24 | from ....utils_rate_limiting import global_rate_limit_route |
35 | 25 | from ... import ( |
36 | 26 | _auth_service, |
|
54 | 44 | from ..._login_service import ( |
55 | 45 | notify_user_confirmation, |
56 | 46 | ) |
57 | | -from ..._models import InputSchema, check_confirm_password_match |
58 | 47 | from ...constants import ( |
59 | 48 | CODE_2FA_SMS_CODE_REQUIRED, |
60 | 49 | MAX_2FA_CODE_RESEND, |
|
71 | 60 | get_plugin_settings, |
72 | 61 | ) |
73 | 62 | from ...web_utils import envelope_response, flash_response |
| 63 | +from .registration_schemas import ( |
| 64 | + InvitationCheck, |
| 65 | + InvitationInfo, |
| 66 | + RegisterBody, |
| 67 | + RegisterPhoneBody, |
| 68 | +) |
74 | 69 |
|
75 | 70 | _logger = logging.getLogger(__name__) |
76 | 71 |
|
77 | 72 |
|
78 | 73 | routes = RouteTableDef() |
79 | 74 |
|
80 | 75 |
|
81 | | -class InvitationCheck(InputSchema): |
82 | | - invitation: str = Field(..., description="Invitation code") |
83 | | - |
84 | | - |
85 | | -class InvitationInfo(InputSchema): |
86 | | - email: LowerCaseEmailStr | None = Field( |
87 | | - None, description="Email associated to invitation or None" |
88 | | - ) |
89 | | - |
90 | | - |
91 | 76 | @routes.post( |
92 | 77 | f"/{API_VTAG}/auth/register/invitations:check", |
93 | 78 | name="auth_check_registration_invitation", |
@@ -122,27 +107,6 @@ async def check_registration_invitation(request: web.Request): |
122 | 107 | return envelope_json_response(InvitationInfo(email=email)) |
123 | 108 |
|
124 | 109 |
|
125 | | -class RegisterBody(InputSchema): |
126 | | - email: LowerCaseEmailStr |
127 | | - password: SecretStr |
128 | | - confirm: SecretStr | None = Field(None, description="Password confirmation") |
129 | | - invitation: str | None = Field(None, description="Invitation code") |
130 | | - |
131 | | - _password_confirm_match = field_validator("confirm")(check_confirm_password_match) |
132 | | - model_config = ConfigDict( |
133 | | - json_schema_extra={ |
134 | | - "examples": [ |
135 | | - { |
136 | | - |
137 | | - "password": "my secret", # NOSONAR |
138 | | - "confirm": "my secret", # optional |
139 | | - "invitation": "33c451d4-17b7-4e65-9880-694559b8ffc2", # optional only active |
140 | | - } |
141 | | - ] |
142 | | - } |
143 | | - ) |
144 | | - |
145 | | - |
146 | 110 | @routes.post(f"/{API_VTAG}/auth/register", name="auth_register") |
147 | 111 | async def register(request: web.Request): |
148 | 112 | """ |
@@ -335,23 +299,6 @@ async def register(request: web.Request): |
335 | 299 | return await _security_service.login_granted_response(request=request, user=user) |
336 | 300 |
|
337 | 301 |
|
338 | | -class RegisterPhoneBody(InputSchema): |
339 | | - email: LowerCaseEmailStr |
340 | | - phone: str = Field( |
341 | | - ..., description="Phone number E.164, needed on the deployments with 2FA" |
342 | | - ) |
343 | | - |
344 | | - |
345 | | -class _PageParams(BaseModel): |
346 | | - expiration_2fa: PositiveInt | None = None |
347 | | - |
348 | | - |
349 | | -class RegisterPhoneNextPage(NextPage[_PageParams]): |
350 | | - logger: str = Field("user", deprecated=True) |
351 | | - level: Literal["INFO", "WARNING", "ERROR"] = "INFO" |
352 | | - message: str |
353 | | - |
354 | | - |
355 | 302 | @routes.post(f"/{API_VTAG}/auth/verify-phone-number", name="auth_register_phone") |
356 | 303 | @session_access_required( |
357 | 304 | name="auth_register_phone", |
|
0 commit comments