public function run()
 {
     require_once dirname(__FILE__) . '/../models/UserOAuth.php';
     require_once dirname(__FILE__) . '/../HOAuthAction.php';
     // provider delete action
     if (Yii::app()->request->isPostRequest && isset($_GET['hoauthDelSN'])) {
         ob_clean();
         ob_clean();
         $userNetwork = UserOAuth::model()->findUser(Yii::app()->user->id, $_GET['hoauthDelSN']);
         if ($userNetwork) {
             $userNetwork->delete();
         }
         Yii::app()->end();
     }
     $userNetworks = UserOAuth::model()->findUser(Yii::app()->user->id);
     $sns = array();
     foreach ($userNetworks as $network) {
         $deleteUrl = '?hoauthDelSN=' . $network->provider;
         try {
             array_push($sns, array('provider' => $network->provider, 'profileUrl' => $network->profileCache->profileURL, 'deleteUrl' => $deleteUrl));
         } catch (Exception $e) {
             echo $e->getMessage();
         }
     }
     $this->render('networksList', array('sns' => $sns));
 }
Пример #2
0
 public function run()
 {
     $config = UserOAuth::getConfig();
     foreach ($config['providers'] as $provider => $settings) {
         if ($settings['enabled']) {
             $this->render('link', array('provider' => $provider));
         }
     }
 }
Пример #3
0
 public function run()
 {
     $config = UserOAuth::getConfig();
     echo CHtml::openTag('div', array('id' => 'hoauthWidget' . $this->id, 'class' => 'hoauthWidget'));
     foreach ($config['providers'] as $provider => $settings) {
         if ($settings['enabled']) {
             $this->render('link', array('provider' => $provider));
         }
     }
     echo CHtml::closeTag('div');
 }
 public function run()
 {
     if (!$this->user) {
         return;
     }
     // find all authorizations from user with id=
     $userOAuths = UserOAuth::model()->findUser($this->user->primaryKey);
     foreach ($userOAuths as $userOAuth) {
         $this->render('link', array('provider' => $userOAuth->provider));
     }
 }
Пример #5
0
 public function run()
 {
     if (!$this->route) {
         $this->route = $this->controller->module ? $this->controller->module->id . '/' . $this->controller->id : $this->controller->id . '/oauth';
     }
     $endpoint_url = Yii::app()->createAbsoluteUrl($this->route);
     $this->endPointUrl = $endpoint_url;
     require_once dirname(__FILE__) . '/models/UserOAuth.php';
     $this->configPath = UserOAuth::getConfigPath();
     $this->controller->renderText($this->getForm($this->configPath, $this->endPointUrl));
     Yii::app()->end();
 }
 public function run()
 {
     $path = dirname(__FILE__);
     if (!$this->route) {
         $endpoint_url = $this->controller->module ? $this->controller->module->id . '/' . $this->controller->id : $this->controller->id;
     } else {
         $endpoint_url = $this->route;
     }
     $endpoint_url = Yii::app()->createAbsoluteUrl($endpoint_url . '/oauth');
     require_once dirname(__FILE__) . '/models/UserOAuth.php';
     $config_path = UserOAuth::getConfigPath();
     include $path . '/hybridauth/install.php';
     Yii::app()->end();
 }
 /**
  * Initiates authorization with specified $provider and 
  * then authenticates the user, when all goes fine
  * 
  * @param mixed $provider provider name for HybridAuth
  * @access protected
  * @return void
  */
 protected function oAuth($provider)
 {
     try {
         // trying to authenticate user via social network
         $oAuth = UserOAuth::model()->authenticate($provider);
         $userProfile = $oAuth->profile;
         // If we already have a user logged in, associate the authenticated
         // provider with the logged-in user
         if (!Yii::app()->user->isGuest) {
             $oAuth->bindTo(Yii::app()->user->id);
         } else {
             $newUser = false;
             if ($oAuth->isBond) {
                 // this social network account is bond to existing local account
                 Yii::log("Logged in with existing link with '{$provider}' provider", CLogger::LEVEL_INFO, 'hoauth.' . __CLASS__);
                 if ($this->useYiiUser) {
                     $user = User::model()->findByPk($oAuth->user_id);
                 } else {
                     $user = call_user_func(array($this->model, 'model'))->findByPk($oAuth->user_id);
                 }
             }
             if (!$oAuth->isBond || !$user) {
                 if (!empty($userProfile->emailVerified)) {
                     // checking whether we already have a user with specified email
                     if ($this->useYiiUser) {
                         $user = User::model()->findByAttributes(array('email' => $userProfile->emailVerified));
                     } else {
                         $user = call_user_func(array($this->model, 'model'))->findByEmail($userProfile->emailVerified);
                     }
                 }
                 if (!isset($user)) {
                     // registering a new user
                     $user = new $this->model($this->scenario);
                     $newUser = true;
                 }
                 if ($this->alwaysCheckPass || $user->isNewRecord) {
                     $user = $this->processUser($user, $userProfile);
                 }
             }
             // checking if current user is not banned or anything else
             // $accessCode == 0 - user shouldn't get access
             // $accessCode == 1 - user may login
             // $accessCode == 2 - user may login, but not now (e.g. the email should be verified and activated)
             $accessCode = 1;
             if (method_exists($this->controller, 'hoauthCheckAccess')) {
                 $accessCode = $this->controller->hoauthCheckAccess($user);
             } elseif ($this->useYiiUser) {
                 $accessCode = $this->yiiUserCheckAccess($user);
             }
             if (!$accessCode) {
                 Yii::app()->end();
             }
             // sign user in
             if ($accessCode === 1) {
                 $identity = $this->useYiiUser ? new DummyUserIdentity($user->primaryKey, $user->email) : new UserIdentity($user->email, null);
                 if (!Yii::app()->user->login($identity, $this->duration)) {
                     throw new Exception("Can't sign in, something wrong with UserIdentity class.");
                 }
             }
             if (!$oAuth->bindTo($user->primaryKey)) {
                 throw new Exception("Error, while binding user to provider:\n\n" . var_export($oAuth->errors, true));
             }
             // user was successfully logged in
             // firing callback
             if (method_exists($this->controller, 'hoauthAfterLogin')) {
                 $this->controller->hoauthAfterLogin($user, $newUser);
             }
             if ($accessCode === 2) {
                 Yii::app()->end();
             }
             // stopping script to let checkAccess() function render new content
         }
     } catch (Exception $e) {
         if (YII_DEBUG) {
             $error = "";
             // Display the received error
             switch ($e->getCode()) {
                 case 0:
                     $error = "Unspecified error.";
                     break;
                 case 1:
                     $error = "Hybriauth configuration error.";
                     break;
                 case 2:
                     $error = "Provider not properly configured.";
                     break;
                 case 3:
                     $error = "Unknown or disabled provider.";
                     break;
                 case 4:
                     $error = "Missing provider application credentials.";
                     break;
                 case 5:
                     $error = "Authentication failed. The user has canceled the authentication or the provider refused the connection.";
                     break;
                 case 6:
                     $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.";
                     $oAuth->logout();
                     break;
                 case 7:
                     $error = "User not connected to the provider.";
                     $oAuth->logout();
                     break;
                 case 8:
                     $error = "Provider does not support this feature.";
                     break;
             }
             $error .= "\n\n<br /><br /><b>Original error message:</b> " . $e->getMessage();
             Yii::log($error, CLogger::LEVEL_INFO, 'hoauth.' . __CLASS__);
             echo $error;
             Yii::app()->end();
         }
     }
     $returnUrl = $this->useYiiUser ? Yii::app()->modules['user']['returnUrl'] : Yii::app()->user->returnUrl;
     Yii::app()->controller->redirect($returnUrl);
 }
Пример #8
0
    /**
     * Initiates authorization with specified $provider and 
     * then authenticates the user, when all goes fine
     * 
     * @param mixed $provider provider name for HybridAuth
     * @access protected
     * @return void
     */
    protected function oAuth($provider)
    {
        try {
            // trying to authenticate user via social network
            $oAuth = UserOAuth::model()->authenticate($provider);
            $this->setOauth($oAuth);
            $accessCode = $this->getAccessCode();
            if ($accessCode === 1) {
                // the authentication was successfull. closing auth window
                ?>
				<script>
					var returnUrl = <?php 
                echo $this->useUserReturnUrl ? CJavaScript::encode(Yii::app()->user->getReturnUrl(false)) : false;
                ?>
;
					if(window.opener) {
						if(returnUrl) {
							window.opener.location.href = returnUrl;
						} else {
							window.opener.location.reload();
						}

						window.close();
					}else{
						window.location.href = returnUrl ? returnUrl : '/';
					}
				</script>
				<?php 
                Yii::app()->end();
            }
        } catch (Exception $e) {
            $this->handleError($e);
        }
        ?>
		<script>
			window.close();
		</script>
		<?php 
    }