Initial commit - Customer Portal for Coolify
This commit is contained in:
36
customer_portal/models/session.py
Executable file
36
customer_portal/models/session.py
Executable file
@@ -0,0 +1,36 @@
|
||||
"""Session model."""
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from customer_portal.models import Base
|
||||
|
||||
|
||||
class Session(Base):
|
||||
"""Login session."""
|
||||
|
||||
__tablename__ = "sessions"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
customer_id = Column(
|
||||
Integer, ForeignKey("customers.id"), nullable=False, index=True
|
||||
)
|
||||
token = Column(String(255), unique=True, nullable=False, index=True)
|
||||
ip_address = Column(String(45))
|
||||
user_agent = Column(Text)
|
||||
expires_at = Column(DateTime, nullable=False)
|
||||
created_at = Column(DateTime, default=lambda: datetime.now(UTC))
|
||||
|
||||
# Relationship
|
||||
customer = relationship("Customer", back_populates="sessions")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Session {self.id} for customer {self.customer_id}>"
|
||||
|
||||
@property
|
||||
def is_valid(self) -> bool:
|
||||
"""Check if session is still valid."""
|
||||
now = datetime.now(UTC)
|
||||
return self.expires_at > now
|
||||
Reference in New Issue
Block a user