From e49f45ba6e2cc836b4548b34bb0c1a76e6ef74aa Mon Sep 17 00:00:00 2001
From: zhinianboke <115088296+zhinianboke@users.noreply.github.com>
Date: Fri, 15 Aug 2025 16:19:44 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E7=95=8C?=
=?UTF-8?q?=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
db_manager.py | 1 +
reply_server.py | 50 ++++++++++++++++++++++++++++++++
static/index.html | 33 +++++++++++++++++++++
static/js/app.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++-
static/login.html | 24 +++++++++++++++-
5 files changed, 179 insertions(+), 2 deletions(-)
diff --git a/db_manager.py b/db_manager.py
index 5db8d8a..f7cfcbc 100644
--- a/db_manager.py
+++ b/db_manager.py
@@ -407,6 +407,7 @@ class DBManager:
INSERT OR IGNORE INTO system_settings (key, value, description) VALUES
('theme_color', 'blue', '主题颜色'),
('registration_enabled', 'true', '是否开启用户注册'),
+ ('show_default_login_info', 'true', '是否显示默认登录信息'),
('smtp_server', '', 'SMTP服务器地址'),
('smtp_port', '587', 'SMTP端口'),
('smtp_user', '', 'SMTP登录用户名(发件邮箱)'),
diff --git a/reply_server.py b/reply_server.py
index 1c9df63..09160c2 100644
--- a/reply_server.py
+++ b/reply_server.py
@@ -1502,10 +1502,35 @@ def get_registration_status():
return {'enabled': True, 'message': '注册功能已开启'} # 出错时默认开启
+@app.get('/login-info-status')
+def get_login_info_status():
+ """获取默认登录信息显示状态(公开接口,无需认证)"""
+ from db_manager import db_manager
+ try:
+ enabled_str = db_manager.get_system_setting('show_default_login_info')
+ logger.debug(f"从数据库获取的登录信息显示设置值: '{enabled_str}'")
+
+ # 如果设置不存在,默认为开启
+ if enabled_str is None:
+ enabled_bool = True
+ else:
+ enabled_bool = enabled_str == 'true'
+
+ return {"enabled": enabled_bool}
+ except Exception as e:
+ logger.error(f"获取登录信息显示状态失败: {e}")
+ # 出错时默认为开启
+ return {"enabled": True}
+
+
class RegistrationSettingUpdate(BaseModel):
enabled: bool
+class LoginInfoSettingUpdate(BaseModel):
+ enabled: bool
+
+
@app.put('/registration-settings')
def update_registration_settings(setting_data: RegistrationSettingUpdate, admin_user: Dict[str, Any] = Depends(require_admin)):
"""更新注册开关设置(仅管理员)"""
@@ -1532,6 +1557,31 @@ def update_registration_settings(setting_data: RegistrationSettingUpdate, admin_
logger.error(f"更新注册设置失败: {e}")
raise HTTPException(status_code=500, detail=str(e))
+@app.put('/login-info-settings')
+def update_login_info_settings(setting_data: LoginInfoSettingUpdate, admin_user: Dict[str, Any] = Depends(require_admin)):
+ """更新默认登录信息显示设置(仅管理员)"""
+ from db_manager import db_manager
+ try:
+ enabled = setting_data.enabled
+ success = db_manager.set_system_setting(
+ 'show_default_login_info',
+ 'true' if enabled else 'false',
+ '是否显示默认登录信息'
+ )
+ if success:
+ log_with_user('info', f"更新登录信息显示设置: {'开启' if enabled else '关闭'}", admin_user)
+ return {
+ 'success': True,
+ 'enabled': enabled,
+ 'message': f"默认登录信息显示已{'开启' if enabled else '关闭'}"
+ }
+ else:
+ raise HTTPException(status_code=500, detail='更新登录信息显示设置失败')
+ except HTTPException:
+ raise
+ except Exception as e:
+ logger.error(f"更新登录信息显示设置失败: {e}")
+ raise HTTPException(status_code=500, detail=str(e))
diff --git a/static/index.html b/static/index.html
index 1919e93..b07bebb 100644
--- a/static/index.html
+++ b/static/index.html
@@ -1568,6 +1568,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 开启后,登录页面将显示默认的用户名和密码信息,方便用户快速登录
+
+
+
+
+
+
+
diff --git a/static/js/app.js b/static/js/app.js
index 7711f41..650ff12 100644
--- a/static/js/app.js
+++ b/static/js/app.js
@@ -7674,9 +7674,10 @@ async function loadSystemSettings() {
outgoingConfigs.style.display = isAdmin ? 'block' : 'none';
}
- // 如果是管理员,加载注册设置和外发配置
+ // 如果是管理员,加载注册设置、登录信息设置和外发配置
if (isAdmin) {
await loadRegistrationSettings();
+ await loadLoginInfoSettings();
await loadOutgoingConfigs();
}
}
@@ -7897,6 +7898,76 @@ async function updateRegistrationSettings() {
}
}
+// 加载默认登录信息设置
+async function loadLoginInfoSettings() {
+ try {
+ const response = await fetch('/system-settings', {
+ headers: {
+ 'Authorization': `Bearer ${authToken}`
+ }
+ });
+
+ if (response.ok) {
+ const settings = await response.json();
+ const checkbox = document.getElementById('showDefaultLoginInfo');
+
+ if (checkbox && settings.show_default_login_info !== undefined) {
+ checkbox.checked = settings.show_default_login_info === 'true';
+ }
+ }
+ } catch (error) {
+ console.error('加载登录信息设置失败:', error);
+ showToast('加载登录信息设置失败', 'danger');
+ }
+}
+
+// 更新默认登录信息设置
+async function updateLoginInfoSettings() {
+ const checkbox = document.getElementById('showDefaultLoginInfo');
+ const statusDiv = document.getElementById('loginInfoStatus');
+ const statusText = document.getElementById('loginInfoStatusText');
+
+ if (!checkbox) return;
+
+ const enabled = checkbox.checked;
+
+ try {
+ const response = await fetch('/login-info-settings', {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${authToken}`
+ },
+ body: JSON.stringify({
+ enabled: enabled
+ })
+ });
+
+ if (response.ok) {
+ const data = await response.json();
+ const message = enabled ? '默认登录信息显示已开启' : '默认登录信息显示已关闭';
+ showToast(message, 'success');
+
+ // 显示状态信息
+ if (statusDiv && statusText) {
+ statusText.textContent = message;
+ statusDiv.style.display = 'block';
+
+ // 3秒后隐藏状态信息
+ setTimeout(() => {
+ statusDiv.style.display = 'none';
+ }, 3000);
+ }
+ } else {
+ const errorData = await response.json();
+ showToast(`更新失败: ${errorData.detail || '未知错误'}`, 'danger');
+ }
+ } catch (error) {
+ console.error('更新登录信息设置失败:', error);
+ showToast('更新登录信息设置失败', 'danger');
+ }
+}
+
// ================================
// 订单管理功能
// ================================
diff --git a/static/login.html b/static/login.html
index 3ceb42d..389460a 100644
--- a/static/login.html
+++ b/static/login.html
@@ -226,7 +226,7 @@
-
+
@@ -659,11 +659,33 @@
}
}
+ // 检查默认登录信息显示状态
+ async function checkLoginInfoStatus() {
+ try {
+ const response = await fetch('/login-info-status');
+ const result = await response.json();
+
+ const defaultLoginInfo = document.getElementById('defaultLoginInfo');
+ if (result.enabled) {
+ defaultLoginInfo.style.display = 'block';
+ } else {
+ defaultLoginInfo.style.display = 'none';
+ }
+ } catch (error) {
+ console.error('检查登录信息显示状态失败:', error);
+ // 出错时默认显示
+ document.getElementById('defaultLoginInfo').style.display = 'block';
+ }
+ }
+
// 事件监听器
document.addEventListener('DOMContentLoaded', function() {
// 检查注册状态
checkRegistrationStatus();
+ // 检查默认登录信息显示状态
+ checkLoginInfoStatus();
+
// 登录方式切换
document.querySelectorAll('input[name="loginType"]').forEach(radio => {
radio.addEventListener('change', switchLoginType);