更新了找回密码错误
This commit is contained in:
parent
c4e2b3e741
commit
f754072e08
@ -435,23 +435,74 @@ class AppServer:
|
|||||||
|
|
||||||
@self.app.route('/api/auth/forgot-password', methods=['POST'])
|
@self.app.route('/api/auth/forgot-password', methods=['POST'])
|
||||||
def forgot_password():
|
def forgot_password():
|
||||||
"""忘记密码"""
|
"""忘记密码 - 根据用户名和手机号找回密码"""
|
||||||
try:
|
try:
|
||||||
data = flask_request.get_json()
|
data = flask_request.get_json()
|
||||||
username = data.get('username')
|
username = data.get('username')
|
||||||
|
phone = data.get('phone')
|
||||||
|
|
||||||
if not username:
|
if not username:
|
||||||
return jsonify({'success': False, 'error': '用户名不能为空'}), 400
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'error': '请输入用户名'
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
if not phone:
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'error': '请输入手机号码'
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
# 验证手机号格式
|
||||||
|
import re
|
||||||
|
phone_pattern = r'^1[3-9]\d{9}$'
|
||||||
|
if not re.match(phone_pattern, phone):
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'error': '手机号格式不正确'
|
||||||
|
}), 400
|
||||||
|
|
||||||
|
# 查询用户信息
|
||||||
|
conn = self.db_manager.get_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT username, password, phone FROM users
|
||||||
|
WHERE username = ? AND phone = ?
|
||||||
|
''', (username, phone))
|
||||||
|
|
||||||
|
user = cursor.fetchone()
|
||||||
|
|
||||||
|
if user:
|
||||||
|
# 用户存在且手机号匹配,返回数据库中存储的实际密码
|
||||||
|
actual_password = user['password']
|
||||||
|
|
||||||
|
self.logger.info(f'用户 {username} 密码查询成功')
|
||||||
|
|
||||||
# 这里应该发送重置密码邮件,简化处理
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'success': True,
|
'success': True,
|
||||||
'message': '密码重置邮件已发送,请查收邮箱'
|
'password': actual_password, # 返回数据库中存储的实际密码
|
||||||
|
'message': '密码找回成功'
|
||||||
})
|
})
|
||||||
|
else:
|
||||||
|
# 检查用户是否存在
|
||||||
|
cursor.execute('SELECT username FROM users WHERE username = ?', (username,))
|
||||||
|
user_exists = cursor.fetchone()
|
||||||
|
|
||||||
|
if not user_exists:
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'error': '用户不存在'
|
||||||
|
}), 400
|
||||||
|
else:
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'error': '手机号不匹配'
|
||||||
|
}), 400
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f'忘记密码处理失败: {e}')
|
self.logger.error(f'忘记密码处理失败: {e}')
|
||||||
return jsonify({'success': False, 'error': str(e)}), 500
|
return jsonify({'success': False, 'error': '处理失败'}), 500
|
||||||
|
|
||||||
# ==================== 用户管理API ====================
|
# ==================== 用户管理API ====================
|
||||||
|
|
||||||
@ -732,10 +783,12 @@ class AppServer:
|
|||||||
|
|
||||||
result = self.config_manager.set_all_device_configs(data)
|
result = self.config_manager.set_all_device_configs(data)
|
||||||
|
|
||||||
# 如果配置设置成功,重启设备数据推送
|
# 如果配置设置成功,异步重启设备数据推送
|
||||||
if result['success']:
|
if result['success']:
|
||||||
|
def restart_devices_async():
|
||||||
|
"""异步重启设备数据推送"""
|
||||||
try:
|
try:
|
||||||
self.logger.info("设备配置更新成功,重启设备数据推送...")
|
self.logger.info("设备配置更新成功,异步重启设备数据推送...")
|
||||||
# 先停止当前的数据推送
|
# 先停止当前的数据推送
|
||||||
if self.is_pushing_data:
|
if self.is_pushing_data:
|
||||||
self.stop_device_push_data()
|
self.stop_device_push_data()
|
||||||
@ -743,11 +796,28 @@ class AppServer:
|
|||||||
|
|
||||||
# 重新启动设备数据推送
|
# 重新启动设备数据推送
|
||||||
self.start_device_push_data()
|
self.start_device_push_data()
|
||||||
result['message'] = result.get('message', '') + ' 设备已重启数据推送。'
|
|
||||||
self.logger.info("设备配置更新并重启数据推送完成")
|
self.logger.info("设备配置更新并重启数据推送完成")
|
||||||
|
|
||||||
|
# 通过SocketIO通知前端重启完成
|
||||||
|
self.socketio.emit('device_restart_complete', {
|
||||||
|
'status': 'success',
|
||||||
|
'message': '设备重启完成'
|
||||||
|
}, namespace='/devices')
|
||||||
|
|
||||||
except Exception as restart_error:
|
except Exception as restart_error:
|
||||||
self.logger.error(f"重启设备数据推送失败: {restart_error}")
|
self.logger.error(f"重启设备数据推送失败: {restart_error}")
|
||||||
result['message'] = result.get('message', '') + f' 但重启设备数据推送失败: {str(restart_error)}'
|
# 通过SocketIO通知前端重启失败
|
||||||
|
self.socketio.emit('device_restart_complete', {
|
||||||
|
'status': 'error',
|
||||||
|
'message': f'设备重启失败: {str(restart_error)}'
|
||||||
|
}, namespace='/devices')
|
||||||
|
|
||||||
|
# 启动异步线程执行重启操作
|
||||||
|
restart_thread = threading.Thread(target=restart_devices_async)
|
||||||
|
restart_thread.daemon = True
|
||||||
|
restart_thread.start()
|
||||||
|
|
||||||
|
result['message'] = result.get('message', '') + ' 设备正在后台重启中,请稍候...'
|
||||||
|
|
||||||
status_code = 200 if result['success'] else 400
|
status_code = 200 if result['success'] else 400
|
||||||
return jsonify(result), status_code
|
return jsonify(result), status_code
|
||||||
|
Loading…
Reference in New Issue
Block a user