aboutsummaryrefslogtreecommitdiffstats
path: root/db/models.py
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2026-09-04 17:09:24 +0200
committerGravatar Tom van der Lee <tom@vanderlee.io>2026-09-04 17:09:24 +0200
commit6b6f20a032eb31d747366c8bc270ca81731eaf6a (patch)
treeada48080495267bebde4ee1251bbbe77d629745f /db/models.py
parent2d22158dd95f76399f5716d556be60c77da04a46 (diff)
downloadserver-6b6f20a032eb31d747366c8bc270ca81731eaf6a.tar.gz
server-6b6f20a032eb31d747366c8bc270ca81731eaf6a.tar.bz2
server-6b6f20a032eb31d747366c8bc270ca81731eaf6a.zip
Fixed pre-commit issuesv3
Diffstat (limited to 'db/models.py')
-rw-r--r--db/models.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/db/models.py b/db/models.py
index 8a01c8c..8946bd2 100644
--- a/db/models.py
+++ b/db/models.py
@@ -1,13 +1,16 @@
1import re 1import re
2from datetime import datetime, UTC 2from datetime import UTC, datetime
3from urllib.parse import urlsplit 3from uuid import UUID, uuid7
4from uuid import uuid4, UUID, uuid7
5 4
6from sqlalchemy import DateTime 5from sqlalchemy import DateTime
7from sqlmodel import SQLModel, Field, Relationship 6from sqlmodel import Field, Relationship, SQLModel
8from starlette.authentication import BaseUser 7from starlette.authentication import BaseUser
9 8
10from authentication.mixins import OAuth2ClientMixin, OAuth2AuthorizationCodeMixin, OAuth2TokenMixin 9from authentication.mixins import (
10 OAuth2AuthorizationCodeMixin,
11 OAuth2ClientMixin,
12 OAuth2TokenMixin,
13)
11from authentication.utils import bcrypt_sha256_hash 14from authentication.utils import bcrypt_sha256_hash
12 15
13 16
@@ -21,7 +24,7 @@ class BaseModel(SQLModel):
21 default=None, 24 default=None,
22 nullable=True, 25 nullable=True,
23 sa_column_kwargs={ 26 sa_column_kwargs={
24 'onupdate': lambda: datetime.now(tz=UTC), 27 "onupdate": lambda: datetime.now(tz=UTC),
25 }, 28 },
26 sa_type=DateTime(timezone=True), 29 sa_type=DateTime(timezone=True),
27 ) 30 )
@@ -39,10 +42,12 @@ class User(BaseModel, BaseUser, table=True):
39 def is_authenticated(self) -> bool: 42 def is_authenticated(self) -> bool:
40 return True 43 return True
41 44
45
42class Session(BaseModel, table=True): 46class Session(BaseModel, table=True):
43 user_id: UUID = Field(foreign_key='user.id', exclude=True) 47 user_id: UUID = Field(foreign_key="user.id", exclude=True)
44 user: User = Relationship() 48 user: User = Relationship()
45 49
50
46class ClientApplication(BaseModel, OAuth2ClientMixin, table=True): 51class ClientApplication(BaseModel, OAuth2ClientMixin, table=True):
47 name: str 52 name: str
48 53
@@ -52,10 +57,12 @@ class ClientApplication(BaseModel, OAuth2ClientMixin, table=True):
52 for pattern in self.redirect_uris 57 for pattern in self.redirect_uris
53 ) 58 )
54 59
60
55class AuthCode(BaseModel, OAuth2AuthorizationCodeMixin, table=True): 61class AuthCode(BaseModel, OAuth2AuthorizationCodeMixin, table=True):
56 user_id: UUID = Field(foreign_key="user.id", ondelete="CASCADE") 62 user_id: UUID = Field(foreign_key="user.id", ondelete="CASCADE")
57 user: User = Relationship() 63 user: User = Relationship()
58 64
65
59class AuthToken(BaseModel, OAuth2TokenMixin, table=True): 66class AuthToken(BaseModel, OAuth2TokenMixin, table=True):
60 user_id: UUID = Field(foreign_key="user.id", ondelete="CASCADE") 67 user_id: UUID = Field(foreign_key="user.id", ondelete="CASCADE")
61 user: User = Relationship() 68 user: User = Relationship()