feat(master): 后台增加师傅密码重置功能并优化师傅端账号安全页面
- 后端后台管理:在师傅管理模块新增 resetpwd 功能,支持重置登录密码、支付密码或全部重置,并联动清理锁定状态与在线令牌 - 视图与脚本:新增 resetpwd.html 弹窗视图并在 master.js 与 index.html 中注册操作按钮与表单联动逻辑 - 师傅端接口:MasterAuth::setPaymentPassword 简化流程,依托已有登录态直接设置6位数字支付密码,并在修改登录密码时自动重置锁定状态 - 师傅端小程序:security.vue 全面升级账号安全中心界面视觉与交互,展示账号信息、认证状态并提供标准弹窗;清理 wxlogin.js 中冗余代码
这个提交包含在:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</div>
|
||||
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
|
||||
data-operate-detail="{:$auth->check('master/detail')}"
|
||||
data-operate-resetpwd="{:$auth->check('master/resetpwd')}"
|
||||
data-operate-edit="{:$auth->check('master/edit')}"
|
||||
data-operate-del="{:$auth->check('master/del')}"
|
||||
width="100%">
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<form id="resetpwd-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
|
||||
{:token()}
|
||||
<div class="panel panel-default panel-form-section">
|
||||
<div class="panel-heading"><h4 class="panel-title">重置师傅密码</h4></div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3">目标师傅:</label>
|
||||
<div class="col-sm-8">
|
||||
<p class="form-control-static">{$row.realname|default=$row.nickname|htmlentities}(ID:{$row.id},手机:{$row.mobile|default='未绑定'|htmlentities})</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3">当前状态:</label>
|
||||
<div class="col-sm-8">
|
||||
<p class="form-control-static">
|
||||
登录密码:
|
||||
{if $hasLoginPassword}<span class="label label-success">已设置</span>{else /}<span class="label label-default">未设置</span>{/if}
|
||||
|
||||
支付密码:
|
||||
{if $hasPaymentPassword}<span class="label label-success">已设置</span>{else /}<span class="label label-default">未设置</span>{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3">重置项目:</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="row[type]" value="login" checked> 仅重置登录密码</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="row[type]" value="payment"> 仅重置支付密码</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="row[type]" value="both"> 同时清空登录密码与支付密码</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" id="new-password-group">
|
||||
<label class="control-label col-sm-3" for="c-new-password">新密码(选填):</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="c-new-password" name="row[new_password]" class="form-control" type="password" autocomplete="new-password" placeholder="留空则清空密码,由师傅在小程序端自行重新设置">
|
||||
<p class="help-block" id="new-password-help">留空将清空原密码并解除锁定,师傅可在“账号安全”中直接重设;若填写,登录密码须6-30位,支付密码须6位数字。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-footer normal-footer text-center">
|
||||
<button type="submit" class="btn btn-warning btn-embossed disabled">确认重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
在新工单中引用
屏蔽一个用户