Initial commit - Customer Portal for Coolify

This commit is contained in:
2025-12-17 10:08:34 +01:00
commit 9fca32567c
153 changed files with 16432 additions and 0 deletions

View 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