feat: v3.1 - 用户密码管理和邮箱验证功能
新增功能: 1. 修改密码功能 - 用户可以修改自己的密码 - 需要验证旧密码 - 新密码至少6位且不能与旧密码相同 2. 邮箱绑定功能 - 用户可以绑定/修改邮箱 - 邮箱格式验证和唯一性检查 - 修改邮箱后需要重新验证 3. 邮箱验证功能 - 发送验证邮件(24小时有效) - 点击邮件链接完成验证 - 验证状态显示 技术实现: - 新增4个数据库字段(email_verified等) - 封装邮件发送工具(utils/email_sender.py) - 新增5个API接口 - 新增修改密码页面 - 集成邮箱管理到个人中心 文件变更: - 修改:app.py, models.py, base_new.html, profile.html - 新增:change_password.html, email_sender.py, migrate_email_verification.py - 文档:server-update.md, SERVER_RESTART_GUIDE.md Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
69
migrate_email_verification.py
Normal file
69
migrate_email_verification.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
添加邮箱验证相关字段的数据库迁移脚本
|
||||
运行方式: python migrate_email_verification.py
|
||||
"""
|
||||
|
||||
from app import create_app
|
||||
from models import db
|
||||
|
||||
def migrate():
|
||||
"""执行数据库迁移"""
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
try:
|
||||
# 添加邮箱验证相关字段
|
||||
with db.engine.connect() as conn:
|
||||
# 检查字段是否已存在
|
||||
result = conn.execute(db.text("""
|
||||
SELECT COUNT(*) as count
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='users' AND column_name='email_verified'
|
||||
"""))
|
||||
exists = result.fetchone()[0] > 0
|
||||
|
||||
if not exists:
|
||||
print("开始添加邮箱验证字段...")
|
||||
|
||||
# 添加 email_verified 字段
|
||||
conn.execute(db.text("""
|
||||
ALTER TABLE users
|
||||
ADD COLUMN email_verified BOOLEAN DEFAULT FALSE COMMENT '邮箱是否已验证'
|
||||
"""))
|
||||
conn.commit()
|
||||
print("✓ 添加 email_verified 字段")
|
||||
|
||||
# 添加 email_verified_at 字段
|
||||
conn.execute(db.text("""
|
||||
ALTER TABLE users
|
||||
ADD COLUMN email_verified_at DATETIME COMMENT '邮箱验证时间'
|
||||
"""))
|
||||
conn.commit()
|
||||
print("✓ 添加 email_verified_at 字段")
|
||||
|
||||
# 添加 email_verify_token 字段
|
||||
conn.execute(db.text("""
|
||||
ALTER TABLE users
|
||||
ADD COLUMN email_verify_token VARCHAR(100) COMMENT '邮箱验证令牌'
|
||||
"""))
|
||||
conn.commit()
|
||||
print("✓ 添加 email_verify_token 字段")
|
||||
|
||||
# 添加 email_verify_token_expires 字段
|
||||
conn.execute(db.text("""
|
||||
ALTER TABLE users
|
||||
ADD COLUMN email_verify_token_expires DATETIME COMMENT '验证令牌过期时间'
|
||||
"""))
|
||||
conn.commit()
|
||||
print("✓ 添加 email_verify_token_expires 字段")
|
||||
|
||||
print("\n✅ 邮箱验证字段迁移完成!")
|
||||
else:
|
||||
print("⚠️ 邮箱验证字段已存在,跳过迁移")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 迁移失败: {str(e)}")
|
||||
raise
|
||||
|
||||
if __name__ == '__main__':
|
||||
migrate()
|
||||
Reference in New Issue
Block a user