✨ Update CRUD utils for users handling password hashing (#106)
* Add some information how to run backand test for local backand development * Bug fixes in backend app * 🎨 Update format * ✅ Use random_email for test_update_user Co-authored-by: Mocsar Kalman <mocsar.kalman@gravityrd.com> Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import Optional
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.user import User
|
||||
from app.schemas.user import UserCreate, UserUpdate
|
||||
from app.schemas.user import UserCreate, UserUpdate, UserInDB
|
||||
from app.core.security import verify_password, get_password_hash
|
||||
from app.crud.base import CRUDBase
|
||||
|
||||
@@ -24,6 +24,15 @@ class CRUDUser(CRUDBase[User, UserCreate, UserUpdate]):
|
||||
db_session.refresh(db_obj)
|
||||
return db_obj
|
||||
|
||||
def update(self, db_session: Session, *, db_obj: User, obj_in: UserUpdate) -> User:
|
||||
if obj_in.password:
|
||||
update_data = obj_in.dict(exclude_unset=True)
|
||||
hashed_password = get_password_hash(obj_in.password)
|
||||
del update_data["password"]
|
||||
update_data["hashed_password"] = hashed_password
|
||||
use_obj_in = UserInDB.parse_obj(update_data)
|
||||
return super().update(db_session, db_obj=db_obj, obj_in=use_obj_in)
|
||||
|
||||
def authenticate(
|
||||
self, db_session: Session, *, email: str, password: str
|
||||
) -> Optional[User]:
|
||||
|
Reference in New Issue
Block a user