|
1 | 1 | from typing import Annotated |
2 | 2 |
|
3 | | -from fastapi import APIRouter, Depends, Query, Request, Response, status |
| 3 | +from fastapi import APIRouter, Depends, Form, Query, Request, Response, status |
4 | 4 | from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html |
5 | 5 | from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse |
6 | 6 | from fastapi.security import OAuth2PasswordRequestForm |
| 7 | +from pydantic import ValidationError |
7 | 8 |
|
8 | 9 | from futuramaapi.routers.services.about.get_about import GetAboutService |
9 | 10 | from futuramaapi.routers.services.auth.auth_cookie_session_user import AuthCookieSessionUserService |
10 | 11 | from futuramaapi.routers.services.auth.get_user_auth import GetUserAuthService, UserAuthMessageType |
| 12 | +from futuramaapi.routers.services.auth.get_user_signup import GetUserSignupService, UserSignupMessageType |
11 | 13 | from futuramaapi.routers.services.auth.logout_cookie_session_user import LogoutCookieSessionUserService |
| 14 | +from futuramaapi.routers.services.auth.signup_cookie_session_user import SignupCookieSessionUserService |
12 | 15 | from futuramaapi.routers.services.changelog.get_changelog import GetChangelogService |
13 | 16 | from futuramaapi.routers.services.index.get_index import GetIndexService |
14 | 17 | from futuramaapi.routers.services.sitemaps.get_sitemap import GetSiteMapService |
@@ -157,6 +160,66 @@ async def logout_cookie_session_user( |
157 | 160 | return await service() |
158 | 161 |
|
159 | 162 |
|
| 163 | +@router.get( |
| 164 | + "/signup", |
| 165 | + include_in_schema=False, |
| 166 | + name="user_signup", |
| 167 | +) |
| 168 | +async def user_signup( |
| 169 | + request: Request, |
| 170 | + message_type: Annotated[ |
| 171 | + UserSignupMessageType | None, |
| 172 | + Query( |
| 173 | + alias="messageType", |
| 174 | + ), |
| 175 | + ] = None, |
| 176 | +) -> Response: |
| 177 | + service: GetUserSignupService = GetUserSignupService( |
| 178 | + message_type=message_type, |
| 179 | + context={ |
| 180 | + "request": request, |
| 181 | + }, |
| 182 | + ) |
| 183 | + return await service() |
| 184 | + |
| 185 | + |
| 186 | +@router.post( |
| 187 | + "/signup", |
| 188 | + include_in_schema=False, |
| 189 | + name="signup_cookie_session_user", |
| 190 | +) |
| 191 | +async def signup_cookie_session_user( # noqa: PLR0913 |
| 192 | + request: Request, |
| 193 | + name: Annotated[str, Form()] = "", |
| 194 | + surname: Annotated[str, Form()] = "", |
| 195 | + email: Annotated[str, Form()] = "", |
| 196 | + username: Annotated[str, Form()] = "", |
| 197 | + password: Annotated[str, Form()] = "", |
| 198 | +) -> RedirectResponse: |
| 199 | + if not all([name.strip(), surname.strip(), email.strip(), username.strip(), password]): |
| 200 | + return RedirectResponse( |
| 201 | + url=f"/signup?messageType={UserSignupMessageType.validation_error}", |
| 202 | + status_code=status.HTTP_302_FOUND, |
| 203 | + ) |
| 204 | + try: |
| 205 | + service: SignupCookieSessionUserService = SignupCookieSessionUserService( |
| 206 | + name=name, |
| 207 | + surname=surname, |
| 208 | + email=email, |
| 209 | + username=username, |
| 210 | + password=password, |
| 211 | + context={ |
| 212 | + "request": request, |
| 213 | + }, |
| 214 | + ) |
| 215 | + except ValidationError: |
| 216 | + return RedirectResponse( |
| 217 | + url=f"/signup?messageType={UserSignupMessageType.validation_error}", |
| 218 | + status_code=status.HTTP_302_FOUND, |
| 219 | + ) |
| 220 | + return await service() |
| 221 | + |
| 222 | + |
160 | 223 | @router.post( |
161 | 224 | "/auth", |
162 | 225 | include_in_schema=False, |
|
0 commit comments