feat(master): 后台增加师傅密码重置功能并优化师傅端账号安全页面
- 后端后台管理:在师傅管理模块新增 resetpwd 功能,支持重置登录密码、支付密码或全部重置,并联动清理锁定状态与在线令牌 - 视图与脚本:新增 resetpwd.html 弹窗视图并在 master.js 与 index.html 中注册操作按钮与表单联动逻辑 - 师傅端接口:MasterAuth::setPaymentPassword 简化流程,依托已有登录态直接设置6位数字支付密码,并在修改登录密码时自动重置锁定状态 - 师傅端小程序:security.vue 全面升级账号安全中心界面视觉与交互,展示账号信息、认证状态并提供标准弹窗;清理 wxlogin.js 中冗余代码
这个提交包含在:
@@ -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();
|
||||
|
||||
在新工单中引用
屏蔽一个用户