2

I am using Yii-eauth for social login. https://github.com/Nodge/yii-eauth Now i am getting username by

Yii::app()->user->name.

I want to fetch email opf user also . How to do this in Yii 1.1 . Thanx in advance

Vikky
  • 43
  • 1
  • 7

2 Answers2

0

I have managed to get email address from linkedin.

There is a class for LinkedIn Login

Change the $scope variable to get email address.

Also, do the settings in LinkedIn App page.

protected $scope = 'r_basicprofile r_emailaddress'; // 'r_fullprofile r_emailaddress';

Also, add email-address to singed request like this:

$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);

Now, your $info will have email-address for you.

Facebook also has solution similar to this.

Pupil
  • 23,834
  • 6
  • 44
  • 66
0

In your protected/componenets/UserIdentity.php File you need to add user email to session like this way:-

 $this->setState('email_of_user',$users->email);

You can use and access this email_of_user variable via echo Yii::app()->user->email_of_user

If this code is not working for you then you need to do following changes in your files:-

In your model/LoginForm.php ,

replace this function,

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 ..
    }

In your protected/componenets/UserIdentity.php file:-

replace this line

class UserIdentity extends CUserIdentity

to

 class UserIdentity extends EAuthUserIdentity

Hope this code will work for you :)

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42