Пример #1
0
 /**
  * @param  string $identity
  * @param  string $token
  * @param  array  $data (Optional)
  * @return \Application\Entity\User
  * @throws InvalidTokenException
  */
 public function signup($identity, $token, array $data = array())
 {
     // validate token
     $gpUser = $this->_requestUserData($token);
     if ($gpUser->getUserId() !== $identity) {
         throw new InvalidTokenException('Invalid identity and token pair');
     }
     // first check existing credentials
     /** @var \Application\Entity\Credentials $credentials */
     $credentials = $this->_getCredentials($identity);
     if (null !== $credentials) {
         // only update token and return user
         $this->updateToken($credentials, $token);
         return $credentials->getUser();
     }
     $attributes = $gpUser->getAttributes();
     $data['email'] = $attributes['payload']['email'];
     // register new user
     $credentials = new Credentials();
     $credentials->setIdentity($identity)->setToken($token)->setType($this->_credentialType)->setStatus(CredentialsStatus::CONFIRMED);
     // retrieve or create new user
     $user = null === $credentials->getUser() ? $this->_findUserByEmailOrCreateNew($data['email']) : $credentials->getUser();
     $user = $this->_updateUser($user, $data, false);
     $user->addCredential($credentials)->setStatus(UserStatus::ACTIVE);
     return $user;
 }
Пример #2
0
 /**
  * @param  string $identity
  * @param  string $token
  * @param  array  $data (Optional)
  * @return \Application\Entity\User
  * @throws InvalidTokenException
  */
 public function signup($identity, $token, array $data = array())
 {
     // validate token
     $fbUser = $this->_requestUserData($token);
     if ($fbUser->getId() !== $identity) {
         throw new InvalidTokenException('Invalid identity and token pair');
     }
     // first check existing credentials
     /** @var \Application\Entity\Credentials $credentials */
     $credentials = $this->_getCredentials($identity);
     if (null !== $credentials) {
         // only update token and return user
         $this->updateToken($credentials, $token);
         return $credentials->getUser();
     }
     // register new user
     $credentials = new Credentials();
     $credentials->setIdentity($identity)->setToken($token)->setType($this->_credentialType)->setStatus(CredentialsStatus::CONFIRMED);
     // retrieve or create new user
     $user = null === $credentials->getUser() ? $this->_findUserByEmailOrCreateNew($fbUser->getField('email')) : $credentials->getUser();
     $user = $this->_updateUser($user, array('email' => $fbUser->getField('email'), 'birthday' => $fbUser->getBirthday(), 'firstname' => $fbUser->getFirstName(), 'lastname' => $fbUser->getLastName(), 'gender' => $fbUser->getGender()), false);
     $user->addCredential($credentials)->setStatus(UserStatus::ACTIVE);
     return $user;
 }