Automated Action 5b55eedd2b Implement User Authentication and Authorization Service
This commit includes:
- User registration and authentication API with JWT
- Password reset functionality
- Role-based access control system
- Database models and migrations with SQLAlchemy and Alembic
- API documentation in README

generated with BackendIM... (backend.im)
2025-05-15 19:46:38 +00:00

31 lines
1.2 KiB
Python

from datetime import datetime
from sqlalchemy import Boolean, Column, DateTime, Integer, String
from sqlalchemy.orm import relationship
from app.db.base_class import Base
from app.utils.security import get_password_hash, verify_password
class User(Base):
id = Column(Integer, primary_key=True, index=True)
email = Column(String, unique=True, index=True, nullable=False)
hashed_password = Column(String, nullable=False)
first_name = Column(String, nullable=True)
last_name = Column(String, nullable=True)
is_active = Column(Boolean, default=True)
is_verified = Column(Boolean, default=False)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
roles = relationship("Role", secondary="userrole", back_populates="users")
password_resets = relationship("PasswordReset", back_populates="user")
def set_password(self, password: str) -> None:
self.hashed_password = get_password_hash(password)
def verify_password(self, password: str) -> bool:
return verify_password(password, self.hashed_password)
def __repr__(self) -> str:
return f"<User {self.email}>"