Пример #1
0
 /**
  * Update existing user, add social loggin
  */
 public function socialUpdate($social)
 {
     // Add social auth
     $userSocial = new UserSocial();
     $userSocial->social_id = $social->getSocialId();
     $userSocial->type = $social->getProvider();
     $userSocial->user_id = $this->getId();
     if ($userSocial->create() === true) {
         return true;
     }
     return false;
 }
Пример #2
0
 public function social(string $driver, Request $request)
 {
     if (!$request->has('code')) {
         return Socialite::with($driver)->redirect();
     }
     /** @var \SocialiteProviders\Manager\OAuth2\User $auth */
     $auth = Socialite::driver($driver)->user();
     $userSocial = (new UserSocial())->where('driver', $driver)->where('uid', $auth->getId())->with(['user'])->first();
     if ($userSocial === null) {
         $user = (new User())->where('email', $auth->getEmail())->first();
         if ($user === null) {
             $user = User::create(['name' => $auth->getName(), 'avatar' => $auth->getAvatar(), 'email' => $auth->getEmail()]);
         }
         $userSocial = UserSocial::create(['driver' => $driver, 'user_id' => $user->id, 'uid' => $auth->getId(), 'avatar' => $auth->getAvatar(), 'email' => $auth->getEmail(), 'name' => $auth->getName()]);
     }
     Auth::login($userSocial->user, true);
     return redirect(route('product.index'));
 }