Source code for codegrade.models.otp_login_single_response
"""The module that defines the ``OTPLoginSingleResponse`` model.
SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""
from __future__ import annotations
import typing as t
from dataclasses import dataclass, field
import cg_request_args as rqa
from ..utils import to_dict
from .user_login_response import UserLoginResponse
[docs]
@dataclass
class OTPLoginSingleResponse(UserLoginResponse):
"""Response when OTP verification succeeds with a single user."""
#: Discriminator for the response type.
type: t.Literal["login"]
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: UserLoginResponse.data_parser.parser.combine(
rqa.FixedMapping(
rqa.RequiredArgument(
"type",
rqa.StringEnum("login"),
doc="Discriminator for the response type.",
),
)
).use_readable_describe(True)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"type": to_dict(self.type),
"user": to_dict(self.user),
"access_token": to_dict(self.access_token),
"restrictions": to_dict(self.restrictions),
"expires_at": to_dict(self.expires_at),
}
return res
@classmethod
def from_dict(
cls: t.Type[OTPLoginSingleResponse], d: t.Dict[str, t.Any]
) -> OTPLoginSingleResponse:
parsed = cls.data_parser.try_parse(d)
res = cls(
type=parsed.type,
user=parsed.user,
access_token=parsed.access_token,
restrictions=parsed.restrictions,
expires_at=parsed.expires_at,
)
res.raw_data = d
return res
import os
if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"):
import datetime
from .extended_user import ExtendedUser
from .session_restriction_data import SessionRestrictionData