From 7784c60c03ec277b456db6e2709383e302d9382b Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Fri, 3 Jul 2026 15:49:08 +0200 Subject: Added basic oauth flow --- db/models.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'db/models.py') diff --git a/db/models.py b/db/models.py index e758671..7e0afb0 100644 --- a/db/models.py +++ b/db/models.py @@ -1,6 +1,8 @@ +from datetime import datetime, UTC from uuid import uuid4, UUID, uuid7 -from sqlmodel import SQLModel, Field +from sqlalchemy import DateTime +from sqlmodel import SQLModel, Field, Relationship from authlib.integrations.sqla_oauth2 import OAuth2ClientMixin, OAuth2AuthorizationCodeMixin, OAuth2TokenMixin from authentication.utils import bcrypt_sha256_hash @@ -8,6 +10,19 @@ from authentication.utils import bcrypt_sha256_hash class BaseModel(SQLModel): id: UUID | None = Field(primary_key=True, default_factory=uuid7) + created: datetime = Field( + default_factory=lambda: datetime.now(tz=UTC), + sa_type=DateTime(timezone=True), + ) + updated: datetime = Field( + default=None, + nullable=True, + sa_column_kwargs={ + 'onupdate': lambda: datetime.now(tz=UTC), + }, + sa_type=DateTime(timezone=True), + ) + class User(BaseModel, table=True): username: str = Field(unique=True, index=True) @@ -18,6 +33,9 @@ class User(BaseModel, table=True): def set_password(self, value): self.password = bcrypt_sha256_hash(value) +class Session(BaseModel, table=True): + user_id: UUID = Field(foreign_key='user.id', exclude=True) + user: User = Relationship() class ClientApplication(BaseModel, OAuth2ClientMixin, table=True): name: str -- cgit v1.2.3