2
2
from typing import Any
3
3
4
4
import bcrypt
5
- from passlib .context import CryptContext
6
5
from pydantic import SecretStr
7
- from sqlalchemy import String , LargeBinary , select
6
+ from sqlalchemy import String , LargeBinary , select , Column
8
7
from sqlalchemy .dialects .postgresql import UUID
9
8
from sqlalchemy .ext .asyncio import AsyncSession
10
9
from sqlalchemy .orm import mapped_column , Mapped
11
10
12
11
from app .models .base import Base
13
12
14
- pwd_context = CryptContext (schemes = ["bcrypt" ], deprecated = "auto" )
15
-
16
13
17
14
class User (Base ):
18
15
id : Mapped [uuid .UUID ] = mapped_column (
@@ -21,21 +18,21 @@ class User(Base):
21
18
email : Mapped [str ] = mapped_column (String , nullable = False , unique = True )
22
19
first_name : Mapped [str ] = mapped_column (String , nullable = False )
23
20
last_name : Mapped [str ] = mapped_column (String , nullable = False )
24
- _password : Mapped [ bytes ] = mapped_column (LargeBinary , nullable = False )
21
+ _password : bytes = Column (LargeBinary , nullable = False )
25
22
26
23
@property
27
24
def password (self ):
28
25
return self ._password .decode ("utf-8" )
29
26
30
27
@password .setter
31
28
def password (self , password : SecretStr ):
32
- _password_string = password .get_secret_value ()
29
+ _password_string = password .get_secret_value (). encode ( "utf-8" )
33
30
self ._password = bcrypt .hashpw (
34
- _password_string . encode ( "utf-8" ) , bcrypt .gensalt ()
31
+ _password_string , bcrypt .gensalt ()
35
32
)
36
33
37
34
def check_password (self , password : SecretStr ):
38
- return pwd_context . verify (password .get_secret_value (), self .password )
35
+ return bcrypt . checkpw (password .get_secret_value (). encode ( "utf-8" ) , self ._password )
39
36
40
37
@classmethod
41
38
async def find (cls , database_session : AsyncSession , where_conditions : list [Any ]):
0 commit comments