22 lines
518 B
Python
22 lines
518 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
from dataclasses import dataclass
|
|
|
|
from app.domain.shared.base_value_object import ValueObject
|
|
from app.domain.users.exceptions import InvalidEmail
|
|
|
|
_EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Email(ValueObject):
|
|
value: str
|
|
|
|
def __post_init__(self) -> None:
|
|
if not _EMAIL_RE.match(self.value):
|
|
raise InvalidEmail(f"Invalid email: {self.value}")
|
|
|
|
def __str__(self) -> str:
|
|
return self.value
|