You've already forked RekomenciBackend
41 lines
953 B
Python
41 lines
953 B
Python
from datetime import UTC, datetime
|
|
from enum import StrEnum
|
|
from typing import NewType, Self
|
|
from uuid import UUID
|
|
|
|
from uuid_utils.compat import uuid7
|
|
|
|
from template_project.application.common.entity import Entity, to_entity
|
|
from template_project.application.user.entity import UserId
|
|
|
|
AuthIdentityId = NewType("AuthIdentityId", UUID)
|
|
|
|
|
|
class AuthMethod(StrEnum):
|
|
EMAIL = "email"
|
|
|
|
|
|
@to_entity
|
|
class AuthIdentity(Entity[AuthIdentityId]):
|
|
user_id: UserId
|
|
method: AuthMethod
|
|
identifier: str
|
|
secret_key: str | None
|
|
|
|
@classmethod
|
|
def factory(
|
|
cls,
|
|
user_id: UserId,
|
|
method: AuthMethod,
|
|
identifier: str,
|
|
secret_key: str | None = None,
|
|
) -> Self:
|
|
return cls(
|
|
id=AuthIdentityId(uuid7()),
|
|
user_id=user_id,
|
|
method=method,
|
|
identifier=identifier,
|
|
secret_key=secret_key,
|
|
created_at=datetime.now(tz=UTC),
|
|
)
|