后台账号体系改造:接入t_admin_数据库账号与前端改密
变更项: 1. 新增 db/admin_account_db.py,提供 t_admin_accounts 表初始化、PBKDF2口令哈希、登录校验、登录信息回写与密码更新能力。 2. DashboardServer 启动时接入账号数据层,自动建表并把旧配置默认账号迁移为数据库账号种子。 3. 重构 auth 登录逻辑:优先走数据库账号鉴权,保留旧配置账号回退;新增 /api/auth/change_password 接口支持在线修改密码。 4. base.html 增加顶部修改密码入口与弹窗表单,前端可直接提交旧密码与新密码完成改密。 5. login.html 增强小屏适配:允许纵向滚动、768以下隐藏展示侧栏并优化输入区间距与字号,修复移动端登录体验。 6. 新增迁移脚本 db/scripts/migrations/20260423_add_admin_account_table.sql,便于独立数据库升级。
This commit is contained in:
@@ -224,6 +224,18 @@
|
||||
transition: all .18s ease !important;
|
||||
}
|
||||
|
||||
.account-btn {
|
||||
color: var(--text-soft) !important;
|
||||
padding: 10px 14px !important;
|
||||
border-radius: 999px !important;
|
||||
transition: all .18s ease !important;
|
||||
}
|
||||
|
||||
.account-btn:hover {
|
||||
color: var(--primary) !important;
|
||||
background: var(--primary-soft) !important;
|
||||
}
|
||||
|
||||
.logout-btn:hover {
|
||||
color: var(--primary) !important;
|
||||
background: var(--primary-soft) !important;
|
||||
@@ -699,6 +711,13 @@
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.password-dialog-tip {
|
||||
margin-top: 8px;
|
||||
color: var(--text-faint);
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="stylesheet" href="/static/css/element-ui/theme-chalk/index.min.css">
|
||||
@@ -741,7 +760,10 @@
|
||||
</div>
|
||||
<div class="user-pill">
|
||||
<span class="user-dot"></span>
|
||||
<span>管理员已登录</span>
|
||||
<span>{{ session.get('username', '管理员') }} 已登录</span>
|
||||
</div>
|
||||
<el-button type="text" class="account-btn" @click="openPasswordDialog">
|
||||
<i class="el-icon-lock"></i> 修改密码
|
||||
</div>
|
||||
<el-button type="text" class="logout-btn" @click="logout">
|
||||
<i class="el-icon-switch-button"></i> 退出
|
||||
@@ -785,6 +807,35 @@
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
title="修改后台登录密码"
|
||||
:visible.sync="passwordDialogVisible"
|
||||
width="460px"
|
||||
:close-on-click-modal="false">
|
||||
<el-form
|
||||
ref="passwordFormRef"
|
||||
:model="passwordForm"
|
||||
:rules="passwordRules"
|
||||
label-width="96px">
|
||||
<el-form-item label="旧密码" prop="old_password">
|
||||
<el-input v-model="passwordForm.old_password" type="password" show-password autocomplete="off" placeholder="请输入当前密码"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码" prop="new_password">
|
||||
<el-input v-model="passwordForm.new_password" type="password" show-password autocomplete="off" placeholder="至少6位"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="确认新密码" prop="confirm_password">
|
||||
<el-input v-model="passwordForm.confirm_password" type="password" show-password autocomplete="off" placeholder="请再次输入新密码"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="password-dialog-tip">
|
||||
提示:修改成功后将立即生效,建议使用强密码(字母、数字、符号组合)。
|
||||
</div>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="passwordDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="passwordSubmitting" @click="submitPasswordChange">确认修改</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
@@ -870,7 +921,37 @@
|
||||
currentView: '1',
|
||||
timeRange: '7',
|
||||
showTimeRangeSelector: false,
|
||||
navGroups: NAV_GROUPS
|
||||
navGroups: NAV_GROUPS,
|
||||
// 账号密码修改弹窗状态。
|
||||
passwordDialogVisible: false,
|
||||
passwordSubmitting: false,
|
||||
passwordForm: {
|
||||
old_password: '',
|
||||
new_password: '',
|
||||
confirm_password: ''
|
||||
},
|
||||
passwordRules: {
|
||||
old_password: [
|
||||
{ required: true, message: '请输入旧密码', trigger: 'blur' }
|
||||
],
|
||||
new_password: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ min: 6, message: '新密码长度至少6位', trigger: 'blur' }
|
||||
],
|
||||
confirm_password: [
|
||||
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
if (value !== this.passwordForm.new_password) {
|
||||
callback(new Error('两次输入的新密码不一致'));
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -948,6 +1029,49 @@
|
||||
}).then(() => {
|
||||
window.location.href = '/logout';
|
||||
});
|
||||
},
|
||||
openPasswordDialog() {
|
||||
// 打开弹窗前重置表单,避免上次输入残留。
|
||||
this.passwordDialogVisible = true;
|
||||
this.passwordSubmitting = false;
|
||||
this.passwordForm = {
|
||||
old_password: '',
|
||||
new_password: '',
|
||||
confirm_password: ''
|
||||
};
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.passwordFormRef) {
|
||||
this.$refs.passwordFormRef.clearValidate();
|
||||
}
|
||||
});
|
||||
},
|
||||
submitPasswordChange() {
|
||||
if (!this.$refs.passwordFormRef) {
|
||||
return;
|
||||
}
|
||||
this.$refs.passwordFormRef.validate((valid) => {
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
this.passwordSubmitting = true;
|
||||
axios.post('/api/auth/change_password', this.passwordForm)
|
||||
.then((response) => {
|
||||
const data = response.data || {};
|
||||
if (!data.success) {
|
||||
this.$message.error(data.error || '修改密码失败');
|
||||
return;
|
||||
}
|
||||
this.$message.success(data.message || '密码修改成功');
|
||||
this.passwordDialogVisible = false;
|
||||
})
|
||||
.catch((error) => {
|
||||
const errorMsg = error?.response?.data?.error || '修改密码失败,请稍后重试';
|
||||
this.$message.error(errorMsg);
|
||||
})
|
||||
.finally(() => {
|
||||
this.passwordSubmitting = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.login-shell {
|
||||
width: min(1120px, calc(100vw - 48px));
|
||||
@@ -200,12 +201,53 @@
|
||||
width: 8px; height: 8px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgba(16,185,129,0.12);
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
.login-shell { grid-template-columns: 1fr; min-height: auto; }
|
||||
body { align-items: flex-start; padding: 18px 14px; }
|
||||
.login-shell { grid-template-columns: 1fr; min-height: auto; width: 100%; border-radius: 24px; }
|
||||
.login-showcase { padding: 34px 28px; }
|
||||
.hero-title { font-size: 34px; }
|
||||
.showcase-metrics { grid-template-columns: 1fr; }
|
||||
.login-panel { padding: 32px 24px; }
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.login-shell {
|
||||
box-shadow: 0 16px 32px rgba(15, 23, 42, 0.12);
|
||||
border-radius: 18px;
|
||||
min-height: 0;
|
||||
}
|
||||
.login-showcase {
|
||||
display: none;
|
||||
}
|
||||
.login-panel {
|
||||
padding: 22px 16px;
|
||||
}
|
||||
.login-card {
|
||||
max-width: none;
|
||||
}
|
||||
.panel-title {
|
||||
font-size: 24px;
|
||||
}
|
||||
.panel-desc {
|
||||
font-size: 13px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
.el-input__inner,
|
||||
.login-button {
|
||||
height: 44px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.panel-footer {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 420px) {
|
||||
body { padding: 12px; }
|
||||
.login-shell { width: 100%; }
|
||||
.login-panel { padding: 16px 12px; }
|
||||
.panel-eyebrow { margin-bottom: 12px; }
|
||||
.panel-title { font-size: 22px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user