Add user and team models with auth routes and admin endpoints
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class UserBase(BaseModel):
|
||||
username: str = Field(description="Username of the user", examples=["Kalle"])
|
||||
|
||||
|
||||
class User(UserBase):
|
||||
id: int = Field(description="ID of the user", examples=[1])
|
||||
team_id: int = Field(description="ID of the team", examples=[1])
|
||||
is_active: bool = Field(
|
||||
default=True, description="Is the user active?", examples=[True]
|
||||
)
|
||||
avatar_id: int = Field(default=0, description="ID of the avatar", examples=[0])
|
||||
is_admin: bool = Field(
|
||||
default=False, description="Is the user an admin?", examples=[False]
|
||||
)
|
||||
last_login: datetime = Field(
|
||||
description="Last login timestamp",
|
||||
examples=["2025-01-01T00:00:00.000Z"],
|
||||
)
|
||||
created_at: datetime = Field(
|
||||
description="Creation timestamp", examples=["2025-01-01T00:00:00.000Z"]
|
||||
)
|
||||
updated_at: datetime = Field(
|
||||
description="Last update timestamp", examples=["2025-01-01T00:00:00.000Z"]
|
||||
)
|
||||
|
||||
@property
|
||||
def has_logged_in(self) -> bool:
|
||||
"""Returns True if the user has ever logged in, False if last_login is the epoch date."""
|
||||
epoch = datetime(1970, 1, 1, 0, 0, 0)
|
||||
return self.last_login and self.last_login > epoch
|
||||
|
||||
|
||||
class CreateUser(UserBase):
|
||||
password: str = Field(description="Password of the user", examples=["sn1rbul4"])
|
||||
team_id: int = Field(description="ID of the team", examples=[1])
|
||||
is_admin: bool = Field(
|
||||
default=False, description="Is the user an admin?", examples=[False]
|
||||
)
|
||||
|
||||
|
||||
class UserLogin(UserBase):
|
||||
password: str = Field(description="Password of the user", examples=["sn1rbul4"])
|
||||
|
||||
|
||||
class UserChangePassword(BaseModel):
|
||||
id: int = Field(description="ID of the user", examples=[1])
|
||||
old_password: str = Field(
|
||||
description="Old password of the user", examples=["sn1rbul4"]
|
||||
)
|
||||
password: str = Field(description="Password of the user", examples=["p1p4l1"])
|
||||
Reference in New Issue
Block a user