1.9
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""邮件服务(假实现:验证码打印到日志;以后替换为 SMTP)"""
|
||||
|
||||
import hashlib
|
||||
import secrets
|
||||
|
||||
|
||||
def generate_code() -> str:
|
||||
"""生成 6 位数字验证码"""
|
||||
return f"{secrets.randbelow(1000000):06d}"
|
||||
|
||||
|
||||
def hash_code(code: str) -> str:
|
||||
return hashlib.sha256(code.encode()).hexdigest()
|
||||
|
||||
|
||||
async def send_verification_email(to_email: str, code: str, purpose: str = "验证"):
|
||||
"""发送验证邮件(开发期假实现:打印到日志)
|
||||
|
||||
生产环境替换此函数为真实 SMTP 发送即可,调用方无需改动。
|
||||
"""
|
||||
print(f"\n{'=' * 50}")
|
||||
print(f"📧 [邮件服务-开发模式] 收件人: {to_email}")
|
||||
print(f"📋 用途: {purpose}")
|
||||
print(f"🔢 验证码: {code}")
|
||||
print(f"{'=' * 50}\n")
|
||||
return True
|
||||
Reference in New Issue
Block a user