本文整理汇总了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'));
}
}
}