Skip to content
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
13 changes: 5 additions & 8 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
from typing import Any

import bcrypt
from passlib.context import CryptContext
from pydantic import SecretStr
from sqlalchemy import String, LargeBinary, select
from sqlalchemy import String, LargeBinary, select, Column
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import mapped_column, Mapped

from app.models.base import Base

pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


class User(Base):
id: Mapped[uuid.UUID] = mapped_column(
Expand All @@ -21,21 +18,21 @@ class User(Base):
email: Mapped[str] = mapped_column(String, nullable=False, unique=True)
first_name: Mapped[str] = mapped_column(String, nullable=False)
last_name: Mapped[str] = mapped_column(String, nullable=False)
_password: Mapped[bytes] = mapped_column(LargeBinary, nullable=False)
_password: bytes = Column(LargeBinary, nullable=False)

@property
def password(self):
return self._password.decode("utf-8")

@password.setter
def password(self, password: SecretStr):
_password_string = password.get_secret_value()
_password_string = password.get_secret_value().encode("utf-8")
self._password = bcrypt.hashpw(
_password_string.encode("utf-8"), bcrypt.gensalt()
_password_string, bcrypt.gensalt()
)

def check_password(self, password: SecretStr):
return pwd_context.verify(password.get_secret_value(), self.password)
return bcrypt.checkpw(password.get_secret_value().encode("utf-8"), self._password)

@classmethod
async def find(cls, database_session: AsyncSession, where_conditions: list[Any]):
Expand Down
Loading