コード例 #1
0
 /**
  * @param SocialiteUser $oauthUserData
  * @param string        $provider
  *
  * @return Authenticatable|bool
  */
 public function registerViaOAuth(SocialiteUser $oauthUserData, $provider)
 {
     if (!($ownerAccount = User::withTrashed()->whereEmail($oauthUserData->email)->first())) {
         $ownerAccount = \Eloquent::unguarded(function () use($oauthUserData) {
             return User::create(['name' => $oauthUserData->name, 'email' => $oauthUserData->email, 'password' => \Hash::make(uniqid("", true))]);
         });
     }
     # If user account is soft-deleted, restore it.
     $ownerAccount->trashed() && $ownerAccount->restore();
     # Update missing user name.
     if (!$ownerAccount->name) {
         $ownerAccount->name = $oauthUserData->name;
         $ownerAccount->save();
     }
     # Event
     \Event::fire(new Registered($ownerAccount, $provider));
     ($doLinkOAuthAccount = $this->linkOAuthAccount($oauthUserData, $provider, $ownerAccount)) && $this->auth->login($ownerAccount, true);
     \Event::fire(new LoggedIn($ownerAccount, $provider));
     return $doLinkOAuthAccount;
 }