feat(user): 后台用户管理增加重置密码功能,并将部署流程默认调整为纯代码部署(不同步数据库)

这个提交包含在:
2026-11-23 17:54:01 +08:00
父节点 c2f3fcc368
当前提交 45ed55b644
共有 13 个文件被更改,包括 272 次插入 和 184 次删除

查看文件

@@ -231,6 +231,81 @@ class User extends Backend
return $this->view->fetch();
}
/**
* 后台重置用户登录密码或支付密码
*/
public function resetpwd($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$uid = (int)$row['id'];
$security = Db::name('user_security')->where('user_id', $uid)->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\AccountSecurity::ensure($uid);
if ($type === 'login' || $type === 'both') {
if ($type === 'login' && $newPassword !== '') {
$salt = \fast\Random::alnum();
$encrypted = Auth::instance()->getEncryptPassword($newPassword, $salt);
Db::name('user')->where('id', $uid)->update(['password' => $encrypted, 'salt' => $salt]);
} else {
Db::name('user')->where('id', $uid)->update(['password' => '', 'salt' => '']);
}
Db::name('user_security')->where('user_id', $uid)->update([
'failed_attempts' => 0,
'locked_until' => 0,
]);
}
if ($type === 'payment' || $type === 'both') {
$payHash = ($type === 'payment' && $newPassword !== '') ? password_hash($newPassword, PASSWORD_DEFAULT) : '';
Db::name('user_security')->where('user_id', $uid)->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\Token::clear($uid);
}
$this->success('密码重置成功');
}
$this->view->assign([
'row' => $row,
'hasLoginPassword' => !empty($row['password']),
'hasPaymentPassword' => $security && (string)$security['payment_password_hash'] !== '',
]);
return $this->view->fetch();
}
/**
* 添加
*/