如何从Yii eauth获取电子邮件?
我正在使用Yii eauth进行社交登录。 现在我得到用户名了如何从Yii eauth获取电子邮件?,yii,yii-extensions,lightopenid,Yii,Yii Extensions,Lightopenid,我正在使用Yii eauth进行社交登录。 现在我得到用户名了 Yii::app()->user->name. 我想获取电子邮件opf用户也。如何在Yii 1.1中实现这一点。Thanx提前我已经设法从linkedin获得了电子邮件地址 有一个用于LinkedIn登录的类 更改$scope变量以获取电子邮件地址 另外,在LinkedIn应用程序页面中进行设置 protected $scope = 'r_basicprofile r_emailaddress'; // 'r_full
Yii::app()->user->name.
我想获取电子邮件opf用户也。如何在Yii 1.1中实现这一点。Thanx提前我已经设法从linkedin获得了电子邮件地址 有一个用于LinkedIn登录的类 更改
$scope
变量以获取电子邮件地址
另外,在LinkedIn应用程序页面中进行设置
protected $scope = 'r_basicprofile r_emailaddress'; // 'r_fullprofile r_emailaddress';
另外,将电子邮件地址添加到签名请求中,如下所示:
$info = $this->makeSignedRequest('http://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url,email-address,positions)', array(), false); // json format not working :(
$info = $this->parseInfo($info);
现在,您的$info
将为您提供电子邮件地址
Facebook也有类似的解决方案。在受保护的/componenets/UserIdentity.php文件中,您需要这样向会话添加用户电子邮件:-
$this->setState('email_of_user',$users->email);
您可以通过echo Yii::app()->user->email\u of\u user
如果此代码不适用于您,则需要对文件进行以下更改:-
在您的模型/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 ..
}
在受保护的/componenets/UserIdentity.php文件中:-
更换这条线
class UserIdentity extends CUserIdentity
到
希望这段代码对你有用:)maybevar\u dump(Yii::app()->user)代码>是否可以帮助您在数据库中为此用户创建用户记录?我正在做的是获取姓名和电子邮件并将其存储在数据库中查看EAuthUserIdentity类第56行。在这里你也可以设置电子邮件。
class UserIdentity extends EAuthUserIdentity