重构共享逻辑并修复值班提醒回执去重

This commit is contained in:
2026-11-22 14:32:13 +08:00
parent 2fb2c5e1ad
commit 982f0df41c
35 changed files with 2345 additions and 571 deletions
+17
View File
@@ -4,10 +4,14 @@ from __future__ import annotations
import hashlib
import hmac
import re
import secrets
import time
ALGORITHM = "pbkdf2_sha256"
ITERATIONS = 240_000
EMAIL_PATTERN = r"^[^@\s]+@[^@\s]+\.[^@\s]+$"
PHONE_PATTERN = r"^1[3-9][0-9]{9}$"
def hash_password(password: str) -> str:
@@ -38,3 +42,16 @@ def new_token() -> str:
def token_digest(token: str) -> str:
"""数据库只保存高熵令牌的摘要,数据库副本不能直接充当登录凭据。"""
return hashlib.sha256(token.encode("utf-8")).hexdigest()
def now_ms() -> int:
"""当前的 Unix 毫秒时间戳。"""
return int(time.time() * 1000)
def valid_email(value: str) -> bool:
return isinstance(value, str) and re.fullmatch(EMAIL_PATTERN, value) is not None
def valid_phone(value: str) -> bool:
return isinstance(value, str) and re.fullmatch(PHONE_PATTERN, value) is not None