diff --git a/auth_backend/auth_plugins/email.py b/auth_backend/auth_plugins/email.py index abf0b3c..5fe1aed 100644 --- a/auth_backend/auth_plugins/email.py +++ b/auth_backend/auth_plugins/email.py @@ -1,5 +1,6 @@ import hashlib import logging +import re from typing import Annotated, Self from annotated_types import MinLen @@ -26,38 +27,12 @@ settings = get_settings() logger = logging.getLogger(__name__) +EMAIL_CONST_REGEX = re.compile( + r'^[a-zA-Z0-9_.+\-%]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$') def check_email(v): - restricted: set[str] = { - '"', - '#', - '&', - "'", - '(', - ')', - '*', - ',', - '/', - ';', - '<', - '>', - '?', - '[', - '\\', - ']', - '^', - '`', - '{', - '|', - '}', - '~', - '\n', - '\r', - } - if "@" not in v: - raise ValueError() - if set(v) & restricted: - raise ValueError() + if not EMAIL_REGEX.match(v): + raise ValueError("Неверный формат email") return v