【发布时间】:2014-12-27 08:43:59
【问题描述】:
我在我的 yii 项目中使用yii eauth extension 通过社交帐户登录。我还阅读了来自 github 和 russian version 的文档,但我不明白如何使用该扩展。也许那个代码:
$serviceName = Yii::app()->request->getQuery('service');
if (isset($serviceName)) {
/** @var $eauth EAuthServiceBase */
$eauth = Yii::app()->eauth->getIdentity($serviceName);
$eauth->redirectUrl = Yii::app()->user->returnUrl;
$eauth->cancelUrl = $this->createAbsoluteUrl('site/sociallogin');
try {
if ($eauth->authenticate()) {
//var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes());
$identity = new EAuthUserIdentity($eauth);
// successful authentication
if ($identity->authenticate()) {
Yii::app()->user->login($identity);
//var_dump($identity->id, $identity->name, Yii::app()->user->id);exit;
// special redirect with closing popup window
$eauth->redirect();
}
else {
// close popup window and redirect to cancelUrl
$eauth->cancel();
}
}
// Something went wrong, redirect to login page
//$this->redirect(array('site/login2'));
$this->render('login2', array());
}
catch (EAuthException $e) {
// save authentication error to session
Yii::app()->user->setFlash('error', 'EAuthException: '.$e->getMessage());
// close popup window and redirect to cancelUrl
$eauth->redirect($eauth->getCancelUrl());
}
}
// default authorization code through login/password ..
$this->render('login2', array());
问题:
1)$eauth->authenticate()和$identity->authenticate()有什么区别?
2) 登录用户设置的“用户”表保存在哪里?
我已经读过这个simular question,这不是我需要的。对不起,如果我问简单的问题,但我真的需要帮助!提前感谢您的任何回复!
【问题讨论】: