public function createOrGetUser(SocialUser $providerUser, $providerName)
 {
     $account = SocialAccount::whereProvider($providerName)->whereProviderUserId($providerUser->getId())->first();
     if ($account) {
         return $account->user;
     }
     $account = new SocialAccount(['provider_user_id' => $providerUser->getId(), 'provider' => $providerName]);
     $user = User::whereEmail($providerUser->getEmail())->first();
     if (!$user) {
         $user = User::create(['email' => $providerUser->getEmail(), 'name' => $providerUser->getName()]);
     }
     $account->user()->associate($user);
     $account->save();
     return $user;
 }
예제 #2
0
 public function createOrGetUser(ProviderUser $providerUser)
 {
     // Cari akun di db
     $account = SocialAccount::whereProvider('facebook')->whereProviderUserId($providerUser->getId())->first();
     if ($account) {
         // Kalo ada > return user
         return $account->user;
     } else {
         // Kalo gaada > register
         $account = new SocialAccount(['provider_user_id' => $providerUser->getId(), 'provider' => 'facebook']);
         $user = User::whereEmail($providerUser->getEmail())->first();
         if (!$user) {
             $user = User::create(['email' => $providerUser->getEmail(), 'name' => $providerUser->getName()]);
         }
         $account->user()->associate($user);
         $account->save();
         return $user;
     }
 }
예제 #3
0
 public function createOrGetUser(ProviderUser $providerUser)
 {
     $account = SocialAccount::whereProvider('facebook')->whereProviderUserId($providerUser->getId())->first();
     if ($account) {
         return $account->user;
     } else {
         $account = new SocialAccount(['provider_user_id' => $providerUser->getId(), 'provider' => 'facebook']);
         $user = User::whereEmail($providerUser->getEmail())->first();
         $email = "";
         if ($providerUser->getEmail() == "") {
             $email = $providerUser->getName();
         } else {
             $email = $providerUser->getEmail();
         }
         if (!$user) {
             $user = User::create(['email' => $email, 'name' => $providerUser->getName()]);
         }
         $account->user()->associate($user);
         $account->save();
         return $user;
     }
 }