✨ 添加用户修改密码功能
- 左边栏添加修改密码按钮 - 添加修改密码弹窗 - 添加 /api/user/password API 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
26
app.py
26
app.py
@@ -2247,6 +2247,32 @@ def get_current_user_vip():
|
||||
return jsonify(vip_info)
|
||||
|
||||
|
||||
@app.route('/api/user/password', methods=['POST'])
|
||||
@login_required
|
||||
def change_user_password():
|
||||
"""用户修改自己的密码"""
|
||||
data = request.get_json()
|
||||
current_password = data.get('current_password')
|
||||
new_password = data.get('new_password')
|
||||
|
||||
if not current_password or not new_password:
|
||||
return jsonify({"error": "请填写完整信息"}), 400
|
||||
|
||||
if len(new_password) < 6:
|
||||
return jsonify({"error": "新密码至少6位"}), 400
|
||||
|
||||
# 验证当前密码
|
||||
user = database.get_user_by_id(current_user.id)
|
||||
if not user or not check_password_hash(user['password_hash'], current_password):
|
||||
return jsonify({"error": "当前密码错误"}), 400
|
||||
|
||||
# 更新密码(使用管理员重置密码的函数,因为已经验证过当前密码了)
|
||||
if database.admin_reset_user_password(current_user.id, new_password):
|
||||
return jsonify({"success": True})
|
||||
else:
|
||||
return jsonify({"error": "密码更新失败"}), 500
|
||||
|
||||
|
||||
@app.route('/api/run_stats', methods=['GET'])
|
||||
@login_required
|
||||
def get_run_stats():
|
||||
|
||||
Reference in New Issue
Block a user