Skip to content

Commit

Permalink
Merge pull request #147 from Qsnh/dev
Browse files Browse the repository at this point in the history
fixed: 社交登录账号登录强制绑定手机号下绑定已存在的手机号
  • Loading branch information
Qsnh authored Dec 28, 2020
2 parents d0a635f + 6c73276 commit da1197b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 27 additions & 13 deletions app/Bus/AuthBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,42 @@ public function socialiteMobileBind($app, $appId, $userData, $mobile)
*/
$socialiteService = app()->make(SocialiteServiceInterface::class);

// 判断当前的社交账号是否已经绑定了账户
// 如果绑定了就不能继续进行绑定的操作
if ($socialiteService->getBindUserId($app, $appId)) {
throw new ServiceException(__('socialite_account_has_bind_user'));
}

/**
* @var UserService $userService
*/
$userService = app()->make(UserServiceInterface::class);

if ($userService->findMobile($mobile)) {
throw new ServiceException(__('mobile has exists'));
// 检测当前手机号用户是否已经绑定同app的账号了
$mobileUser = $userService->findMobile($mobile);
if ($mobileUser) {
$bindSocialites = $socialiteService->userSocialites($mobileUser['id']);
$apps = array_column($bindSocialites, 'app');
if (in_array($app, $apps)) {
throw new ServiceException(__('socialite_account_has_bind_user'));
}
}

/**
* @var ConfigService $configService
*/
$configService = app()->make(ConfigServiceInterface::class);
if ($mobileUser) {
$user = $mobileUser;
} else {
// 如果手机号还没有创建用户则创建新用户
/**
* @var ConfigService $configService
*/
$configService = app()->make(ConfigServiceInterface::class);
$defaultAvatar = url($configService->getMemberDefaultAvatar());

if ($socialiteService->getBindUserId($app, $appId)) {
throw new ServiceException(__('socialite_account_has_bind_user'));
}
$nickname = $userData['nickname'] ? $userData['nickname'] . Str::random(3) : Str::random(6);
$avatar = $userData['avatar'] ?? $defaultAvatar;

// 创建新用户
$nickname = $userData['nickname'] ? $userData['nickname'] . Str::random(3) : Str::random(6);
$avatar = $userData['avatar'] ?? url($configService->getMemberDefaultAvatar());
$user = $userService->createWithMobile($mobile, '', $nickname, $avatar);
$user = $userService->createWithMobile($mobile, '', $nickname, $avatar);
}

// 将社交账号与新用户绑定
$socialiteService->bindApp($user['id'], $app, $appId, $userData);
Expand Down
2 changes: 1 addition & 1 deletion app/Meedu/MeEdu.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

class MeEdu
{
const VERSION = 'v3.7.1';
const VERSION = 'v3.7.2';
}

0 comments on commit da1197b

Please sign in to comment.