This commit introduces a system to revoke tokens by storing their `jti` in a new `RevokedToken` model. It includes APIs for logging out (revoking a current token) and logging out from all devices (revoking all tokens). Additionally, token validation now checks revocation status during the decode process.
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from sqlalchemy import Column, String, JSON, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
from .base import Base, TimestampMixin, UUIDMixin
|
|
|
|
|
|
class User(Base, UUIDMixin, TimestampMixin):
|
|
__tablename__ = 'users'
|
|
|
|
email = Column(String, unique=True, nullable=False, index=True)
|
|
password_hash = Column(String, nullable=False)
|
|
first_name = Column(String, nullable=False)
|
|
last_name = Column(String, nullable=False)
|
|
phone_number = Column(String)
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
is_superuser = Column(Boolean, default=False, nullable=False)
|
|
preferences = Column(JSON)
|
|
|
|
# Fix relationships with explicit foreign_keys
|
|
created_events = relationship("Event", back_populates="creator", foreign_keys="Event.created_by")
|
|
|
|
# Specify which foreign key to use in EventManager (this is the key fix)
|
|
managed_events = relationship(
|
|
"EventManager",
|
|
back_populates="user",
|
|
foreign_keys="EventManager.user_id"
|
|
)
|
|
guest_profiles = relationship("Guest", back_populates="user", foreign_keys="Guest.user_id")
|
|
revoked_tokens = relationship("RevokedToken", back_populates="user", cascade="all, delete")
|
|
|
|
def __repr__(self):
|
|
return f"<User {self.email}>" |