当前位置: 首页>>代码示例>>PHP>>正文


PHP YumUser::registerByHybridAuth方法代码示例

本文整理汇总了PHP中YumUser::registerByHybridAuth方法的典型用法代码示例。如果您正苦于以下问题:PHP YumUser::registerByHybridAuth方法的具体用法?PHP YumUser::registerByHybridAuth怎么用?PHP YumUser::registerByHybridAuth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YumUser的用法示例。


在下文中一共展示了YumUser::registerByHybridAuth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loginByHybridAuth

 public function loginByHybridAuth($provider)
 {
     if (!Yum::module()->loginType & UserModule::LOGIN_BY_HYBRIDAUTH) {
         throw new CException(400, 'Hybrid authentification is not allowed');
     }
     if (!Yum::hasModule('profile')) {
         throw new CException(400, 'Hybrid auth needs the profile submodule to be enabled');
     }
     Yii::import('user.vendors.hybridauth.Hybrid.Auth', true);
     Yii::import('user.profile.models.*');
     require_once Yum::module()->hybridAuthConfigFile;
     try {
         $hybridauth = new Hybrid_Auth(Yum::module()->hybridAuthConfigFile);
         $providers = Yum::module()->hybridAuthProviders;
         if (count($providers) == 0) {
             throw new CException('No Hybrid auth providers enabled in configuration file');
         }
         if (!in_array($provider, $providers)) {
             throw new CException('Requested provider is not enabled in configuration file');
         }
         $success = $hybridauth->authenticate($provider);
         if ($success && $success->isUserConnected()) {
             // User found and authenticated at foreign party. Is he already
             // registered at our application?
             $hybridAuthProfile = $success->getUserProfile();
             $user = $this->getUserByEmail($hybridAuthProfile->email);
             if (!$user && !YumProfile::model()->findByAttributes(array('email' => $hybridAuthProfile->email))) {
                 // No, he is not, so we register the user and sync the profile fields
                 $user = new YumUser();
                 if (!$user->registerByHybridAuth($hybridAuthProfile)) {
                     Yum::setFlash(Yum::t('Registration by external provider failed'));
                     $this->redirect(Yum::module()->returnUrl);
                 } else {
                     Yum::setFlash('Registration successful');
                 }
             }
             $identity = new YumUserIdentity($user->username, null);
             if ($identity->authenticate(true)) {
                 Yum::log(Yum::t('User {username} logged in by hybrid {provider}', array('{username}' => $hybridAuthProfile->displayName, '{email}' => $hybridAuthProfile->displayName, '{provider}' => $provider)));
                 Yii::app()->user->login($identity, Yum::module()->cookieDuration);
             } else {
                 Yum::setFlash(Yum::t('Login by external provider failed'));
             }
             $this->redirect(Yum::module()->returnUrl);
         }
     } catch (Exception $e) {
         if (Yum::module()->debug) {
             throw new CException($e->getMessage());
         } else {
             throw new CHttpException(403, Yum::t('Permission denied'));
         }
     }
 }
开发者ID:kumarsivarajan,项目名称:yii-user-management,代码行数:53,代码来源:YumAuthController.php


注:本文中的YumUser::registerByHybridAuth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。