feat(master): 后台增加师傅密码重置功能并优化师傅端账号安全页面

- 后端后台管理:在师傅管理模块新增 resetpwd 功能,支持重置登录密码、支付密码或全部重置,并联动清理锁定状态与在线令牌
- 视图与脚本:新增 resetpwd.html 弹窗视图并在 master.js 与 index.html 中注册操作按钮与表单联动逻辑
- 师傅端接口:MasterAuth::setPaymentPassword 简化流程,依托已有登录态直接设置6位数字支付密码,并在修改登录密码时自动重置锁定状态
- 师傅端小程序:security.vue 全面升级账号安全中心界面视觉与交互,展示账号信息、认证状态并提供标准弹窗;清理 wxlogin.js 中冗余代码
这个提交包含在:
2026-11-24 18:02:35 +08:00
父节点 55a8d6e921
当前提交 b259c8ec30
共有 8 个文件被更改,包括 522 次插入 和 201 次删除

查看文件

@@ -841,4 +841,80 @@ class Master extends Backend
}
$this->success($target === 'disabled' ? '已停用该师傅账号并强制下线' : '已恢复启用该师傅账号');
}
/**
* 后台重置师傅登录密码或支付密码
*/
public function resetpwd($ids = null)
{
$id = (int)($ids ?: $this->request->param('ids'));
$row = $this->model->find($id);
if (!$row) {
$this->error(__('No Results were found'));
}
$mid = (int)$row['id'];
$security = Db::name('master_security')->where('master_id', $mid)->find();
if ($this->request->isPost()) {
$this->token();
$params = $this->request->post('row/a', []);
$type = trim((string)($params['type'] ?? ''));
$newPassword = (string)($params['new_password'] ?? '');
if (!in_array($type, ['login', 'payment', 'both'], true)) {
$this->error('请选择有效的重置类型');
}
if ($type === 'login' && $newPassword !== '' && !preg_match('/^\S{6,30}$/', $newPassword)) {
$this->error('新登录密码须为6至30位非空字符');
}
if ($type === 'payment' && $newPassword !== '' && !preg_match('/^\d{6}$/', $newPassword)) {
$this->error('新支付密码须为6位数字');
}
Db::startTrans();
try {
\app\common\library\MasterSecurity::ensure($mid);
if ($type === 'login' || $type === 'both') {
if ($type === 'login' && $newPassword !== '') {
$salt = \fast\Random::alnum();
$encrypted = \app\common\library\MasterAuth::instance()->getEncryptPassword($newPassword, $salt);
Db::name('master')->where('id', $mid)->update(['password' => $encrypted, 'salt' => $salt, 'updatetime' => time()]);
} else {
Db::name('master')->where('id', $mid)->update(['password' => '', 'salt' => '', 'updatetime' => time()]);
}
Db::name('master_security')->where('master_id', $mid)->update([
'failed_attempts' => 0,
'locked_until' => 0,
]);
}
if ($type === 'payment' || $type === 'both') {
$payHash = ($type === 'payment' && $newPassword !== '') ? password_hash($newPassword, PASSWORD_DEFAULT) : '';
Db::name('master_security')->where('master_id', $mid)->update([
'payment_password_hash' => $payHash,
'payment_failed_attempts' => 0,
'payment_locked_until' => 0,
]);
}
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
$this->error('重置失败:' . $e->getMessage());
}
if ($type === 'login' || $type === 'both') {
\app\common\library\MasterToken::clear($mid);
}
$this->success('密码重置成功');
}
$this->view->assign([
'row' => $row,
'hasLoginPassword' => !empty($row['password']),
'hasPaymentPassword' => $security && (string)$security['payment_password_hash'] !== '',
]);
return $this->view->fetch();
}
}