Files
Lotty/src/backend/api/v1/auth/schemas.py
T

67 lines
1.4 KiB
Python

from typing import ClassVar
from ninja import ModelSchema, Schema
from pydantic import Field
from apps.users.models import User, UserRole
class LoginIn(Schema):
username: str = Field(
...,
min_length=1,
max_length=150,
description="Username of the account",
)
password: str = Field(
...,
min_length=1,
description="Account password",
)
class TokenPairOut(Schema):
access: str = Field(
...,
description=(
"Short-lived JWT access token (used in Authorization header)"
),
)
refresh: str = Field(
...,
description=(
"Long-lived JWT refresh token (used to obtain a new access token)"
),
)
class TokenRefreshIn(Schema):
refresh: str = Field(
...,
min_length=1,
description="A valid, non-expired refresh token",
)
class TokenRefreshOut(Schema):
access: str = Field(
...,
description="Newly issued JWT access token",
)
class MeOut(ModelSchema):
role: UserRole
class Meta:
model = User
fields: ClassVar[tuple[str, ...]] = (
User.id.field.name,
User.username.field.name,
User.email.field.name,
User.role.field.name,
User.first_name.field.name,
User.last_name.field.name,
User.is_active.field.name,
)