Download models/session_token.py from tayyaba98/full_stack_web_application: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/tayyaba98/full_stack_web_application/resolve/main/models/session_token.py
- Command line
-
hf download hf://spaces/tayyaba98/full_stack_web_application/models/session_token.py
-
curl -L -o session_token.py https://huggingface.co/spaces/tayyaba98/full_stack_web_application/resolve/main/models/session_token.py
1.9 kB
| """ | |
| SQLAlchemy ORM model for SessionToken entity. | |
| This module defines the database schema for the session_tokens table. | |
| Tracks active JWT sessions for logout and revocation functionality. | |
| """ | |
| from datetime import datetime | |
| from sqlalchemy import DateTime, ForeignKey, Integer, Text | |
| from sqlalchemy.orm import Mapped, mapped_column | |
| from core.database import Base | |
| class SessionToken(Base): | |
| """ | |
| SQLAlchemy ORM model for SessionToken entity. | |
| Represents the session_tokens table in PostgreSQL database. | |
| Stores JWT tokens for session management and logout functionality. | |
| Attributes: | |
| id: Primary key, auto-incrementing integer | |
| user_id: Foreign key to users table | |
| token: JWT token string (unique) | |
| expires_at: Token expiration timestamp | |
| created_at: Timestamp when token was created | |
| """ | |
| __tablename__ = "session_tokens" | |
| # Primary key with auto-increment | |
| id: Mapped[int] = mapped_column( | |
| Integer, | |
| primary_key=True, | |
| autoincrement=True | |
| ) | |
| # Foreign key to users table | |
| user_id: Mapped[int] = mapped_column( | |
| Integer, | |
| ForeignKey("users.id", ondelete="CASCADE"), | |
| nullable=False, | |
| index=True | |
| ) | |
| # JWT token string (unique for lookup) | |
| token: Mapped[str] = mapped_column( | |
| Text, | |
| unique=True, | |
| nullable=False, | |
| index=True | |
| ) | |
| # Token expiration timestamp | |
| expires_at: Mapped[datetime] = mapped_column( | |
| DateTime, | |
| nullable=False, | |
| index=True | |
| ) | |
| # Automatic timestamp on creation | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime, | |
| default=datetime.utcnow, | |
| nullable=False | |
| ) | |
| def __repr__(self) -> str: | |
| """String representation for debugging""" | |
| return f"<SessionToken(id={self.id}, user_id={self.user_id}, expires_at={self.expires_at})>" | |