修复所有bug并添加新功能
- 修复添加账号按钮无反应问题
- 添加账号备注字段(可选)
- 添加账号设置按钮(修改密码/备注)
- 修复用户反馈���能
- 添加定时任务执行日志
- 修复容器重启后账号加载问题
- 修复所有JavaScript语法错误
- 优化账号加载机制(4层保障)
🤖 Generated with Claude Code
This commit is contained in:
53
app_utils.py
53
app_utils.py
@@ -280,6 +280,59 @@ def check_user_ownership(user_id: int, resource_type: str,
|
||||
return False, "系统错误"
|
||||
|
||||
|
||||
def verify_and_consume_captcha(session_id: str, code: str, captcha_storage: dict, max_attempts: int = 5) -> Tuple[bool, str]:
|
||||
"""
|
||||
验证并消费验证码
|
||||
|
||||
Args:
|
||||
session_id: 验证码会话ID
|
||||
code: 用户输入的验证码
|
||||
captcha_storage: 验证码存储字典
|
||||
max_attempts: 最大尝试次数,默认5次
|
||||
|
||||
Returns:
|
||||
Tuple[bool, str]: (是否成功, 消息)
|
||||
- 成功时返回 (True, "验证成功")
|
||||
- 失败时返回 (False, 错误消息)
|
||||
|
||||
Example:
|
||||
success, message = verify_and_consume_captcha(
|
||||
captcha_session,
|
||||
captcha_code,
|
||||
captcha_storage,
|
||||
max_attempts=5
|
||||
)
|
||||
if not success:
|
||||
return jsonify({"error": message}), 400
|
||||
"""
|
||||
import time
|
||||
|
||||
# 检查验证码是否存在
|
||||
if session_id not in captcha_storage:
|
||||
return False, "验证码已过期或不存在,请重新获取"
|
||||
|
||||
captcha_data = captcha_storage[session_id]
|
||||
|
||||
# 检查过期时间
|
||||
if captcha_data["expire_time"] < time.time():
|
||||
del captcha_storage[session_id]
|
||||
return False, "验证码已过期,请重新获取"
|
||||
|
||||
# 检查尝试次数
|
||||
if captcha_data.get("failed_attempts", 0) >= max_attempts:
|
||||
del captcha_storage[session_id]
|
||||
return False, f"验证码错误次数过多({max_attempts}次),请重新获取"
|
||||
|
||||
# 验证代码(不区分大小写)
|
||||
if captcha_data["code"].lower() != code.lower():
|
||||
captcha_data["failed_attempts"] = captcha_data.get("failed_attempts", 0) + 1
|
||||
return False, "验证码错误"
|
||||
|
||||
# 验证成功,删除验证码(防止重复使用)
|
||||
del captcha_storage[session_id]
|
||||
return True, "验证成功"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 测试代码
|
||||
print("测试应用工具模块...")
|
||||
|
||||
Reference in New Issue
Block a user