Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants. Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""نرمالسازی شماره موبایل و کد OTP — مشترک بین Core و Identity."""
|
||
from __future__ import annotations
|
||
|
||
import re
|
||
|
||
MOBILE_PATTERN = re.compile(r"^09\d{9}$")
|
||
|
||
|
||
def normalize_otp_digits(value: str | None) -> str | None:
|
||
if value is None:
|
||
return None
|
||
s = str(value).strip()
|
||
if not s:
|
||
return None
|
||
persian = "۰۱۲۳۴۵۶۷۸۹"
|
||
arabic = "٠١٢٣٤٥٦٧٨٩"
|
||
latin = "0123456789"
|
||
trans = str.maketrans(persian + arabic, latin + latin)
|
||
s = s.translate(trans)
|
||
s = "".join(c for c in s if c.isdigit())
|
||
return s if s else None
|
||
|
||
|
||
def normalize_mobile(raw: str) -> str:
|
||
"""تبدیل به فرمت 09xxxxxxxxx."""
|
||
digits = normalize_otp_digits(raw)
|
||
if not digits:
|
||
raise ValueError("شماره موبایل نامعتبر است")
|
||
if digits.startswith("0098"):
|
||
digits = digits[4:]
|
||
elif digits.startswith("98") and len(digits) >= 12:
|
||
digits = digits[2:]
|
||
if len(digits) == 10 and not digits.startswith("0"):
|
||
digits = "0" + digits
|
||
if len(digits) == 11 and digits.startswith("0"):
|
||
if not MOBILE_PATTERN.match(digits):
|
||
raise ValueError("شماره موبایل باید با 09 شروع شود و ۱۱ رقم باشد")
|
||
return digits
|
||
raise ValueError("شماره موبایل باید با 09 شروع شود و ۱۱ رقم باشد")
|