From 8150e53a5b56741076f87debe74e8be670e6ff32 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 23 Feb 2022 16:24:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=88=91=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Auth/SocialiteAuthController.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php b/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php index 8cf5ebb6..54ca6579 100644 --- a/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php +++ b/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php @@ -135,23 +135,24 @@ class SocialiteAuthController extends Controller $socialiteUser = SocialiteUser::firstOrCreate($socialite); $user = null; $input = $request->input(); + $phone = $input['phone']; switch ($type) { case 'default'://手机号+密码 - $user = User::where('phone', $input['phone'])->first(); + $user = User::where('phone', $phone)->first(); //手机号不存在,或者密码错误 if (! $user?->verifyPassword($input['password'])) { throw new BizException(__('Incorrect account or password')); } break; - case 'sms_code'://手机号+验证码 + case 'sms-code'://手机号+验证码 app(SmsCodeService::class)->validate( $input['phone'], SmsCode::TYPE_REGISTER, $input['verify_code'] ); - $user = User::where('phone', $input['phone'])->first(); + $user = User::where('phone', $phone)->first(); break; - case 'wechat_mini'://微信小程序解密手机号 + case 'wechat-mini'://微信小程序解密手机号 //解密失败 $app = EasyWeChatFactory::miniProgram([ 'app_id' => config('wechat.mini_program.default.app_id', ''), @@ -177,7 +178,9 @@ class SocialiteAuthController extends Controller $user = User::where('phone', $phone)->first(); break; } - + if (empty($phone)) { + throw new BizException('系统错误,未找到手机号'); + } //走登录逻辑 if ($user) { $token = $this->loginUser($user, $request); @@ -187,15 +190,14 @@ class SocialiteAuthController extends Controller $inviter = $this->findUserByCode((string) Arr::get($input, 'inviter_code')); try { DB::beginTransaction(); - - $user = User::create( - array_merge($input, [ + $user = User::create([ + 'phone' => $phone, 'password' => Str::random(6), //先随机一个密码 'phone_verified_at' => $time, 'register_ip' => $ip, 'last_login_at' => $time, 'last_login_ip' => $ip, - ]), + ], $inviter ); From 6b603e725dfc11fe0a4496be799ac49921013023 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Wed, 23 Feb 2022 16:38:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Api/Http/Controllers/Auth/SocialiteAuthController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php b/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php index 54ca6579..c4b11b97 100644 --- a/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php +++ b/app/Endpoint/Api/Http/Controllers/Auth/SocialiteAuthController.php @@ -135,7 +135,7 @@ class SocialiteAuthController extends Controller $socialiteUser = SocialiteUser::firstOrCreate($socialite); $user = null; $input = $request->input(); - $phone = $input['phone']; + $phone = $input['phone'] ?? ''; switch ($type) { case 'default'://手机号+密码 $user = User::where('phone', $phone)->first();