Ejemplo n.º 1
0
 /**
  * Register a new user using their Github account.
  *
  * @param  string $code
  * @return \Tricks\User
  */
 public function register($code)
 {
     $token = $this->provider->getAccessToken('authorization_code', ['code' => $code]);
     $userDetails = $this->provider->getUserDetails($token);
     $verifiedEmails = $this->getVerifiedEmails($token->accessToken);
     $userDetails->email = $this->getPrimaryEmail($verifiedEmails);
     $profile = $this->profiles->findByUid($userDetails->uid);
     if (is_null($profile)) {
         $user = $this->users->findByEmail($userDetails->email);
         if (is_null($user)) {
             $user = $this->users->createFromGithubData($userDetails);
         }
         $profile = $this->profiles->createFromGithubData($userDetails, $user, $token->accessToken);
     } else {
         $profile = $this->profiles->updateToken($profile, $token->accessToken);
         $user = $profile->user;
     }
     return $user;
 }