Skip to content

Alpha/task17 - Added check password endpoint #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/api/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from app.api.deps import get_db, get_user
from app.core.config.auth import config as config_auth
from app.crud.user import UserCRUD
from app.schemas.auth import ChangePasswordRequest
from app.schemas.auth import ChangePasswordRequest, CheckPasswordRequest
from app.schemas.common.api_response import ApiGeneralResponse
from app.schemas.user import Token, UserCreate, UserRead, UserRole, UserUpdate
from app.services.auth import AuthService
Expand Down Expand Up @@ -76,6 +76,19 @@ def login_for_access_token(
)


@router.post("/check-password")
def check_password(
current_user: Annotated[UserRead, Depends(get_user)],
request: CheckPasswordRequest,
) -> ApiGeneralResponse:
if not AuthService.verify_password(password=request.password, hashed=current_user.hashed_password):
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Incorrect password")

return ApiGeneralResponse(
message="Password is correct",
)


@router.post("/change-password")
def change_password(
db: Annotated[Database[dict[str, Any]], Depends(get_db)],
Expand Down
4 changes: 4 additions & 0 deletions app/schemas/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
class ChangePasswordRequest(BaseModel):
old_password: str
new_password: str


class CheckPasswordRequest(BaseModel):
password: str