在您的 protected/componenets/UserIdentity.php 文件中,您需要像这样将用户电子邮件添加到会话中:-
$this->setState('email_of_user',$users->email);
您可以通过echo Yii::app()->user->email_of_user 使用和访问此 email_of_user 变量
如果此代码不适合您,那么您需要在文件中进行以下更改:-
在您的 model/LoginForm.php 中,
替换这个函数,
public function actionLogin() {
$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/login');
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/login'));
}
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 ..
}
在您的 protected/componenets/UserIdentity.php 文件中:-
替换这一行
class UserIdentity extends CUserIdentity
到
class UserIdentity extends EAuthUserIdentity
希望这段代码对你有用:)