
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)
23 lines
881 B
Python
23 lines
881 B
Python
from datetime import datetime
|
|
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class PasswordReset(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("user.id", ondelete="CASCADE"), nullable=False)
|
|
token = Column(String, unique=True, index=True, nullable=False)
|
|
is_used = Column(Integer, default=0, nullable=False) # 0 = not used, 1 = used
|
|
expires_at = Column(DateTime, nullable=False)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="password_resets")
|
|
|
|
def is_expired(self) -> bool:
|
|
return datetime.utcnow() > self.expires_at
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<PasswordReset user_id={self.user_id}>" |