From e90a217048f626f98d1b2c5d7cf76b935dcfc5f0 Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Tue, 19 Sep 2023 17:39:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DresetPassword=E6=96=B9?= =?UTF-8?q?=E6=B3=95bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/UserLogic.php | 8 +++++++- app/common/validate/login/PasswordValidate.php | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/api/logic/UserLogic.php b/app/api/logic/UserLogic.php index 897a72dd..595ea803 100644 --- a/app/api/logic/UserLogic.php +++ b/app/api/logic/UserLogic.php @@ -15,6 +15,11 @@ class UserLogic extends BaseLogic public static function resetPassword(array $params): bool { try { + //验证手机号码 + $user = User::field('id')->where('phone',$params['phone'])->findOrEmpty(); + if($user->isEmpty()){ + throw new \Exception('该手机号未注册'); + } // 校验验证码 $smsDriver = new SmsDriver(); if (!$smsDriver->verify($params['phone'], $params['code'], NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA)) { @@ -24,7 +29,8 @@ class UserLogic extends BaseLogic $passwordSalt = Config::get('project.unique_identification'); $password = create_password($params['password'], $passwordSalt); // 更新 - User::where('phone', $params['phone'])->update(['password' => $password]); + $user->password = $password; + $user->save(); return true; } catch (\Exception $e) { self::setError($e->getMessage()); diff --git a/app/common/validate/login/PasswordValidate.php b/app/common/validate/login/PasswordValidate.php index 17710dfb..17910cd3 100644 --- a/app/common/validate/login/PasswordValidate.php +++ b/app/common/validate/login/PasswordValidate.php @@ -16,7 +16,7 @@ class PasswordValidate extends BaseValidate 'phone' => 'require|mobile', 'code' => 'require', 'old_password' => 'require', - 'password' => 'require|length:6,20', + 'password' => 'require|length:6,20|different:old_password', 'password_confirm' => 'require|confirm', ]; @@ -27,6 +27,7 @@ class PasswordValidate extends BaseValidate 'code.require' => '请填写验证码', 'password.require' => '请输入新密码', 'password.length' => '密码须在6-25位之间', + 'password.different' => '新密码不能和原密码一样', 'password_confirm.require' => '请确认密码', 'password_confirm.confirm' => '确认密码和新密码不一致', 'old_password.require' => '请输入原密码',