6
0
Fork 0

Merge branch '1.x' of gitee.com:zi-chunsheng-e-commerce/mall-server into 1.x

release
李静 2022-02-23 17:44:58 +08:00
commit 650dfe02f9
1 changed files with 11 additions and 9 deletions

View File

@ -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
);