/**
  * @param              $provider
  * @param AbstractUser $providerUser
  *
  * @return User
  *
  * @internal param \Laravel\Socialite\Two\User $user
  */
 public function create($provider, AbstractUser $providerUser)
 {
     $name = explode(' ', $providerUser->getName());
     $userData = ['first_name' => $name[0], 'last_name' => isset($name[1]) ? $name[1] : '', 'email' => $providerUser->getEmail(), 'avatar' => $providerUser->getAvatar(), 'status' => User::STATUS_CONFIRMED];
     DB::beginTransaction();
     $user = $this->registrar->create($userData);
     $userProvider = App::make(UserProvider::class, [['provider' => $provider, 'provider_id' => $providerUser->getId()]]);
     $user->providers()->save($userProvider);
     DB::commit();
     return $user;
 }
Exemple #2
0
 /**
  * Create a new profile from Github data.
  *
  * @param \Laravel\Socialite\AbstractUser $userDetails
  * @param \App\User                           $user
  * @param string                              $token
  *
  * @return \App\Profile
  */
 public function createFromGithubData(OAuthUser $details, User $user, $token)
 {
     $profile = $this->getNew();
     $profile->uid = $details->getId();
     $profile->username = $details->getNickname();
     $profile->name = $details->getName();
     $profile->email = $details->getEmail();
     $profile->location = $details['location'];
     $profile->description = $details['blog'];
     $profile->image_url = $details->getAvatar();
     $profile->access_token = $details->token;
     $profile->user_id = $user->id;
     $profile->save();
     return $profile;
 }
Exemple #3
0
 public function addSocial(AbstractUser $socialUser, $provider)
 {
     $refreshToken = isset($socialUser->refreshToken) && $socialUser->refreshToken ? $socialUser->refreshToken : null;
     $this->socials()->create(['provider' => $provider, 'social_id' => $socialUser->getId(), 'email' => $socialUser->getEmail(), 'avatar' => $socialUser->getAvatar(), 'token' => $socialUser->token, 'refresh_token' => $refreshToken, 'expires_in' => $socialUser->expiresIn]);
 }
Exemple #4
0
 public function updateFromProvider(AbstractUser $socialUser, $provider)
 {
     $refreshToken = isset($socialUser->refreshToken) && $socialUser->refreshToken ? $socialUser->refreshToken : null;
     $attributes = ['user_id' => $this->user_id, 'provider' => $provider, 'social_id' => $socialUser->getId(), 'email' => $socialUser->getEmail(), 'avatar' => $socialUser->getAvatar(), 'token' => $socialUser->token, 'refresh_token' => $refreshToken, 'expires_in' => $socialUser->expiresIn];
     $this->updateOrCreate(array_only($attributes, ['user_id', 'provider', 'email']), $attributes);
 }
Exemple #5
0
 /**
  * Create a new user in the database using GitHub data.
  *
  * @param \Laravel\Socialite\AbstractUser $data
  *
  * @return \App\User
  */
 public function createFromGithubData(OAuthUser $data)
 {
     $user = $this->getNew();
     $username = $data->getNickname();
     $isAvailable = is_null($this->findByUsername($username));
     $isAllowed = $this->usernameIsAllowed($username);
     $user->username = $username;
     if (!$isAvailable or !$isAllowed) {
         $user->username .= '_' . str_random(3);
         Session::flash('username_required', true);
     }
     $user->email = $data->getEmail();
     $user->photo = $data->getAvatar() ?: '';
     $user->save();
     Session::flash('password_required', true);
     return $user;
 }