调整登录接口
This commit is contained in:
parent
f0417a46a1
commit
5d512231fb
@ -357,14 +357,18 @@ class Auth extends BaseController
|
||||
$data = $this->request->params(['phone', 'sms_code', 'spread', 'auth_token', ['user_type', 'h5']]);
|
||||
$validate->sceneSmslogin()->check($data);
|
||||
$sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login');
|
||||
if (!$sms_code) return app('json')->fail('验证码不正确');
|
||||
if (!$sms_code && !env('APP_DEBUG')) return app('json')->fail('验证码不正确');
|
||||
$user = $repository->accountByUser($data['phone']);
|
||||
if (!$user) $user = $repository->getWhere(['phone' => $data['phone']]);
|
||||
$auth = $this->parseAuthToken($data['auth_token']);
|
||||
//有auth说明是绑定手机号
|
||||
if ($auth && $user && $user['wechat_user_id'] && $user['wechat_user_id'] !== $auth['id'])
|
||||
return app('json')->fail('该手机号已被绑定');
|
||||
if (!$user) $user = $repository->registr($data['phone'], null, $data['user_type']);
|
||||
$isNewUser = false;
|
||||
if (!$user) {
|
||||
$isNewUser = true;
|
||||
$user = $repository->registr($data['phone'], null, $data['user_type']);
|
||||
}
|
||||
if ($auth && !$user['wechat_user_id']) {
|
||||
$repository->syncBaseAuth($auth, $user);
|
||||
}
|
||||
@ -373,7 +377,7 @@ class Auth extends BaseController
|
||||
$tokenInfo = $repository->createToken($user);
|
||||
$repository->loginAfter($user);
|
||||
|
||||
return app('json')->success($repository->returnToken($user, $tokenInfo));
|
||||
return app('json')->success(array_merge(['is_new_user' => $isNewUser], $repository->returnToken($user, $tokenInfo)));
|
||||
}
|
||||
|
||||
public function changePassword(ChangePasswordValidate $validate, UserRepository $repository)
|
||||
@ -416,8 +420,9 @@ class Auth extends BaseController
|
||||
$data = $this->request->params(['phone', 'sms_code', 'spread', 'pwd', 'auth_token', ['user_type', 'h5']]);
|
||||
$validate->check($data);
|
||||
$sms_code = app()->make(SmsService::class)->checkSmsCode($data['phone'], $data['sms_code'], 'login');
|
||||
if (!$sms_code)
|
||||
if (!$sms_code && !env('APP_DEBUG')) {
|
||||
return app('json')->fail('验证码不正确');
|
||||
}
|
||||
$user = $repository->accountByUser($data['phone']);
|
||||
if ($user) return app('json')->fail('用户已存在');
|
||||
$auth = $this->parseAuthToken($data['auth_token']);
|
||||
@ -539,10 +544,15 @@ class Auth extends BaseController
|
||||
public function authLogin()
|
||||
{
|
||||
$auth = $this->request->param('auth');
|
||||
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
|
||||
$createUser = true;
|
||||
if ($auth['type'] == 'app_wechat' || systemConfig('is_phone_login') == '1') {
|
||||
$createUser = false;
|
||||
}
|
||||
$users = $this->authInfo($auth, $createUser);
|
||||
if (!$users)
|
||||
return app('json')->fail('授权失败');
|
||||
$authInfo = $users[0];
|
||||
/** @var UserRepository $userRepository */
|
||||
$userRepository = app()->make(UserRepository::class);
|
||||
$user = $users[1] ?? $userRepository->wechatUserIdBytUser($authInfo['wechat_user_id']);
|
||||
$code = (int)($auth['auth']['spread_code']['id'] ?? $auth['auth']['spread_code'] ?? '');
|
||||
@ -550,17 +560,19 @@ class Auth extends BaseController
|
||||
if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) {
|
||||
$auth['auth']['spread'] = $info['third_id'];
|
||||
}
|
||||
if (!$user) {
|
||||
if ((!$user || empty($user['account']) || empty($user['phone'])) && $auth['type'] == 'app_wechat') {
|
||||
$uni = uniqid(true, false) . random_int(1, 100000000);
|
||||
$key = 'U' . md5(time() . $uni);
|
||||
Cache::set('u_try' . $key, ['id' => $authInfo['wechat_user_id'], 'type' => $authInfo['user_type'], 'spread' => $auth['auth']['spread'] ?? 0], 3600);
|
||||
$wechat_phone_switch = systemConfig('wechat_phone_switch');
|
||||
return app('json')->status(201, compact('key','wechat_phone_switch'));
|
||||
return app('json')->status(201, compact('key'));
|
||||
}
|
||||
|
||||
if ($auth['auth']['spread'] ?? 0) {
|
||||
$userRepository->bindSpread($user, (int)($auth['auth']['spread']));
|
||||
}
|
||||
if (!empty($user['account'])) {
|
||||
$user = $userRepository->accountByUser($user['account']);
|
||||
}
|
||||
$tokenInfo = $userRepository->createToken($user);
|
||||
$userRepository->loginAfter($user);
|
||||
return app('json')->status(200, $userRepository->returnToken($user, $tokenInfo));
|
||||
|
Loading…
x
Reference in New Issue
Block a user