|
1 | 1 | from datetime import timedelta |
2 | 2 | from typing import Annotated, Any |
3 | 3 |
|
4 | | -from fastapi import APIRouter, Depends, HTTPException |
5 | | -from fastapi.responses import HTMLResponse |
6 | | -from fastapi.security import OAuth2PasswordRequestForm |
7 | | - |
8 | 4 | from app import crud |
9 | 5 | from app.api.deps import CurrentUser, SessionDep, get_current_active_superuser |
10 | 6 | from app.core import security |
11 | 7 | from app.core.config import settings |
12 | 8 | from app.core.security import get_password_hash |
13 | 9 | from app.models import Message, NewPassword, Token, UserPublic |
14 | | -from app.utils import ( |
15 | | - generate_password_reset_token, |
16 | | - generate_reset_password_email, |
17 | | - send_email, |
18 | | - verify_password_reset_token, |
19 | | -) |
| 10 | +from app.utils import (generate_password_reset_token, |
| 11 | + generate_reset_password_email, send_email, |
| 12 | + verify_password_reset_token) |
| 13 | +from fastapi import APIRouter, Depends, HTTPException |
| 14 | +from fastapi.responses import HTMLResponse |
| 15 | +from fastapi.security import OAuth2PasswordRequestForm |
20 | 16 |
|
21 | 17 | router = APIRouter(tags=["login"]) |
22 | 18 |
|
@@ -86,15 +82,16 @@ def reset_password(session: SessionDep, body: NewPassword) -> Message: |
86 | 82 | user = crud.get_user_by_email(session=session, email=email) |
87 | 83 | if not user: |
88 | 84 | raise HTTPException( |
89 | | - status_code=404, |
90 | | - detail="The user with this email does not exist in the system.", |
| 85 | + status_code=404, detail="The user with this email does not exist." |
91 | 86 | ) |
92 | | - elif not user.is_active: |
| 87 | + if not user.is_active: |
93 | 88 | raise HTTPException(status_code=400, detail="Inactive user") |
94 | | - hashed_password = get_password_hash(password=body.new_password) |
95 | | - user.hashed_password = hashed_password |
96 | | - session.add(user) |
97 | | - session.commit() |
| 89 | + |
| 90 | + crud.update_user( |
| 91 | + session=session, |
| 92 | + db_user=user, |
| 93 | + user_in={"password": body.new_password}, |
| 94 | + ) |
98 | 95 | return Message(message="Password updated successfully") |
99 | 96 |
|
100 | 97 |
|
|
0 commit comments