Пример #1
0
 /**
  * authenticate
  *
  * @param Credential $credential
  *
  * @return  integer
  * @throws \Exception
  */
 public function authenticate(Credential $credential)
 {
     if (!class_exists('Hybrid_Auth')) {
         throw new \LogicException('Please install hybridauth/hybridauth first.');
     }
     if (!$credential->_provider) {
         $this->status = Authentication::INVALID_CREDENTIAL;
         return false;
     }
     $provider = $credential->_provider;
     $providers = $this->warder->app->get('social_login', array());
     // Check provider supported
     if (!in_array($provider, array_keys($providers))) {
         if (WINDWALKER_DEBUG) {
             throw new \DomainException('Social Login Provider: ' . $provider . ' not supported.');
         }
         $this->status = Authentication::INVALID_CREDENTIAL;
         return false;
     }
     // Start auth
     $auth = $this->getHybridAuth($this->getHAConfig());
     $adapter = $this->doAuthenticate($provider, $auth);
     // Process different data
     $method = 'process' . ucfirst($provider);
     if (!is_callable(array($this, $method))) {
         throw new \LogicException(__CLASS__ . '::' . $method . '() not exists.');
     }
     // Process for different providers
     $this->{$method}($adapter, $credential);
     $userProfile = $adapter->getUserProfile();
     // Default data
     $credential->avatar = $userProfile->photoURL;
     $credential->params = json_encode(array('raw_profile' => $userProfile));
     $this->prepareUserData($adapter, $credential);
     // Check User Socials
     $userSocialMapper = new UserSocialMapper();
     $mapping = array('identifier' => $userProfile->identifier, 'provider' => $provider);
     $socialMapping = $userSocialMapper->findOne($mapping);
     // Check Socials
     if ($socialMapping->isNull() || User::get($socialMapping->user_id)->isNull()) {
         $createUser = true;
         // Check user exists
         if ($credential->_loginName) {
             $user = User::get(array($credential->_loginName => $credential->{$credential->_loginName}));
             $createUser = $user->isNull();
         }
         if ($createUser) {
             $user = $this->createUser($credential);
         }
         $socialMapping = new Data($mapping);
         $socialMapping->user_id = $user->id;
         $userSocialMapper->createOne($socialMapping);
     }
     $user = User::get($socialMapping->user_id);
     $this->postAuthenticate($user, $socialMapping, $credential, $adapter);
     $credential->bind($user);
     $this->status = Authentication::SUCCESS;
     return true;
 }
Пример #2
0
 /**
  * onAfterDelete
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onAfterDelete(Event $event)
 {
     UserSocialMapper::delete(array('user_id' => $this->id));
 }