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>
|
||||
@@ -12,7 +12,7 @@ use think\Db;
|
||||
*/
|
||||
class MasterAuth extends MasterBase
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
|
||||
protected $noNeedLogin = ['login', 'wxPhoneLogin'];
|
||||
|
||||
/**
|
||||
* 师傅手机号 + 密码登录(H5调试/账号密码通道)
|
||||
@@ -71,40 +71,12 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 师傅端微信小程序 OpenID 静默/授权登录
|
||||
* 师傅端微信小程序 OpenID 静默登录(已下线,统一走微信手机号授权登录)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function wxlogin()
|
||||
{
|
||||
$code = trim((string)$this->request->post('code'));
|
||||
$nickname = trim((string)$this->request->post('nickname'));
|
||||
$avatar = trim((string)$this->request->post('avatar'));
|
||||
if ($code === '') {
|
||||
$this->error('缺少微信登录凭证 code');
|
||||
}
|
||||
|
||||
$wx = WxLogin::jscode2session($code, 'master');
|
||||
if (isset($wx['error'])) {
|
||||
$this->error($wx['error'], ['wx_errcode' => isset($wx['errcode']) ? (int)$wx['errcode'] : 0]);
|
||||
}
|
||||
|
||||
$ret = WxLogin::provisionMaster(
|
||||
$wx['openid'],
|
||||
isset($wx['unionid']) ? $wx['unionid'] : '',
|
||||
isset($wx['session_key']) ? $wx['session_key'] : '',
|
||||
$nickname,
|
||||
$avatar
|
||||
);
|
||||
if (!$this->masterAuth->direct($ret['master_id'])) {
|
||||
$this->error($this->masterAuth->getError() ?: '登录失败');
|
||||
}
|
||||
|
||||
$this->success('登录成功', [
|
||||
'token' => $this->masterAuth->getToken(),
|
||||
'expires' => 2592000,
|
||||
'masterinfo' => $this->profileData(),
|
||||
'is_new' => $ret['is_new'],
|
||||
]);
|
||||
$this->error('师傅端已取消静默登录,请使用微信手机号授权登录');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,6 +116,10 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
$ret = WxLogin::provisionMasterWithMobile($mobile, $openid, $unionid, $sessionKey);
|
||||
$masterRow = Db::name('master')->field('status')->where('id', $ret['master_id'])->find();
|
||||
if ($masterRow && isset($masterRow['status']) && $masterRow['status'] !== 'normal') {
|
||||
$this->error('师傅账号已被禁用');
|
||||
}
|
||||
if (!$this->masterAuth->direct($ret['master_id'])) {
|
||||
$this->error($this->masterAuth->getError() ?: '登录失败');
|
||||
}
|
||||
@@ -176,21 +152,28 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全状态查询(登录密码 / 支付密码)
|
||||
* 安全状态查询(登录密码 / 支付密码 / 绑定手机号 / 实名状态)
|
||||
*/
|
||||
public function securityStatus()
|
||||
{
|
||||
$mid = $this->masterId();
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
$master = Db::name('master')->field('password,mobile,verify_status')->where('id', $mid)->find();
|
||||
$security = Db::name('master_security')->where('master_id', $mid)->find();
|
||||
$rawMobile = trim((string)($master['mobile'] ?? ''));
|
||||
$maskedMobile = strlen($rawMobile) === 11
|
||||
? (substr($rawMobile, 0, 3) . '****' . substr($rawMobile, -4))
|
||||
: $rawMobile;
|
||||
|
||||
$this->success('', [
|
||||
'has_login_password' => !empty($master['password']),
|
||||
'has_payment_password' => $security && $security['payment_password_hash'] !== '',
|
||||
'mobile' => $maskedMobile,
|
||||
'verify_status' => (string)($master['verify_status'] ?? 'draft'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置或修改师傅登录密码
|
||||
* 设置或修改师傅登录密码(未设置时直接设置,已设置时需校验原密码)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function changeLoginPassword()
|
||||
@@ -202,7 +185,7 @@ class MasterAuth extends MasterBase
|
||||
$this->error('登录密码须为6至30位非空字符');
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
$master = Db::name('master')->field('password')->where('id', $mid)->find();
|
||||
if (!empty($master['password'])) {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'login', $old);
|
||||
@@ -211,19 +194,23 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
$ignoreOld = false;
|
||||
} else {
|
||||
$this->verifyBoundPhone($this->request->post('phone_code', ''), (string)$master['mobile']);
|
||||
$ignoreOld = true;
|
||||
}
|
||||
|
||||
if (!$this->masterAuth->changepwd($new, $old, $ignoreOld)) {
|
||||
$this->error($this->masterAuth->getError() ?: '设置失败');
|
||||
}
|
||||
MasterSecurity::ensure($mid);
|
||||
Db::name('master_security')->where('master_id', $mid)->update([
|
||||
'failed_attempts' => 0,
|
||||
'locked_until' => 0,
|
||||
]);
|
||||
MasterToken::clear($mid);
|
||||
$this->success('登录密码已更新,请重新登录');
|
||||
}
|
||||
|
||||
/**
|
||||
* 首次设置师傅支付密码(支持已设登录密码走登录密码验证,或未设登录密码走绑定微信手机号验证)
|
||||
* 首次设置师傅支付密码
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function setPaymentPassword()
|
||||
@@ -234,20 +221,6 @@ class MasterAuth extends MasterBase
|
||||
$this->error('支付密码须为6位数字');
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
$phoneCode = trim((string)$this->request->post('phone_code', ''));
|
||||
if ($phoneCode !== '') {
|
||||
$this->verifyBoundPhone($phoneCode, (string)($master['mobile'] ?? ''));
|
||||
} elseif (!empty($master['password'])) {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'login', (string)$this->request->post('login_password', ''));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
$this->error('请先验证绑定手机号或设置登录密码');
|
||||
}
|
||||
|
||||
MasterSecurity::ensure($mid);
|
||||
$updated = Db::name('master_security')
|
||||
->where('master_id', $mid)
|
||||
@@ -260,7 +233,7 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改师傅支付密码
|
||||
* 修改师傅支付密码(需校验原支付密码)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function changePaymentPassword()
|
||||
@@ -286,18 +259,6 @@ class MasterAuth extends MasterBase
|
||||
$this->success('支付密码修改成功');
|
||||
}
|
||||
|
||||
protected function verifyBoundPhone($code, $mobile)
|
||||
{
|
||||
if (trim((string)$code) === '') {
|
||||
$this->error('请先验证绑定的微信手机号');
|
||||
}
|
||||
$phone = WxLogin::getPhoneNumber((string)$code, 'master');
|
||||
$verified = isset($phone['purePhoneNumber']) ? (string)$phone['purePhoneNumber'] : (string)($phone['phoneNumber'] ?? '');
|
||||
if (isset($phone['error']) || $verified === '' || !hash_equals((string)$mobile, $verified)) {
|
||||
$this->error('手机号验证失败,请使用绑定手机号重新验证');
|
||||
}
|
||||
}
|
||||
|
||||
protected function profileData()
|
||||
{
|
||||
$mid = $this->masterId();
|
||||
|
||||
在新工单中引用
屏蔽一个用户