-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Chefies/feat/auth-profile-picture
Feat/auth profile picture
- Loading branch information
Showing
9 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from fastapi import FastAPI | ||
|
||
import cefies.internal.firestore # noqa: F401 -- Intended to initialize Firebase | ||
from cefies.routes import index_router, auth_router | ||
from cefies.routes import index_router, auth_router, profile_router | ||
|
||
app = FastAPI(root_path="/api") | ||
app.include_router(index_router) | ||
app.include_router(auth_router) | ||
app.include_router(profile_router) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from fastapi import Form, UploadFile, File | ||
|
||
from cefies.models.forms.base import BaseForm | ||
|
||
class RegisterForm(BaseForm): | ||
def __init__( | ||
self, | ||
email: str = Form(...), | ||
name: str = Form(...), | ||
password: str = Form(...), | ||
avatar: UploadFile = File(...), | ||
): | ||
self.email = email | ||
self.name = name | ||
self.password = password | ||
self.avatar = avatar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class BaseForm: | ||
def to_dict(self): | ||
return self.__dict__.copy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import Annotated | ||
from pydantic import BaseModel, StringConstraints | ||
|
||
|
||
class ProfileData(BaseModel): | ||
email: str | ||
name: str | ||
avatar: str | ||
|
||
class ChangePasswordData(BaseModel): | ||
password: Annotated[str, StringConstraints(min_length=8)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from cefies.routes.index import router as index_router | ||
from cefies.routes.auth import router as auth_router | ||
|
||
from cefies.routes.profile import router as profile_router | ||
|
||
__all__ = [ | ||
"index_router", | ||
"auth_router", | ||
"profile_router", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Annotated | ||
from fastapi import APIRouter, Depends | ||
from fastapi.responses import JSONResponse | ||
|
||
from cefies.models.db.user import User | ||
from cefies.models.profile import ProfileData, ChangePasswordData | ||
from cefies.security import get_current_user, get_password_hash | ||
|
||
|
||
router = APIRouter(prefix="/profile") | ||
|
||
|
||
@router.get("/") | ||
def get_profile( | ||
user: Annotated[User, Depends(get_current_user)], | ||
): | ||
return ProfileData(**user.to_dict()) | ||
|
||
@router.patch("/password") | ||
def change_password( | ||
user: Annotated[User, Depends(get_current_user)], | ||
data: ChangePasswordData, | ||
): | ||
user.password = get_password_hash(data.password) | ||
user.save() | ||
return JSONResponse(content={"detail": "password changed"}, status_code=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters