thyseus / yii-user-management

a user management module collection for the yii framework
186 stars 122 forks source link

Trying to get property of non-object when I login with facebook #165

Open leonardoburchi opened 10 years ago

leonardoburchi commented 10 years ago

I enabled hybridauth and Facebook provider, but when I click on Facebook button to login I get the error "Trying to get property of non-object". The stack trace says:

106 $hybridAuthProfile = $success->getUserProfile(); 107 $user = $this->getUser($hybridAuthProfile->displayName); 108 if(!$user && !YumProfile::model()->findByAttributes(array( 109 'email' => $hybridAuthProfile->email))) { 110 // No, he is not, so we register the user and sync the profile fields 111 $user = new YumUser(); 112 if(!$user->registerByHybridAuth($hybridAuthProfile)) { 113 Yum::setFlash(Yum::t('Registration by external provider failed')); 114 $this->redirect(Yum::module()->returnUrl); 115 } else Yum::setFlash('Registration successful'); 116 } 117 118 $identity = new YumUserIdentity($user->username, null); 119 120 if($identity->authenticate(true)) { 121 Yum::log(Yum::t('User {username} logged in by hybrid {provider}', array( 122 '{username}' => $hybridAuthProfile->displayName, 123 '{email}' => $hybridAuthProfile->displayName, 124 '{provider}' => $provider))); 125 126 Yii::app()->user->login($identity, Yum::module()->cookieDuration); 127 } else 128 Yum::setFlash(Yum::t('Login by external provider failed')); 129 130 $this->redirect(Yum::module()->returnUrl);

YumAuthController.php(191): YumAuthController->loginByHybridAuth("Facebook") 186 $this->redirect(Yum::module()->returnUrl);
187 188 $this->layout = Yum::module()->loginLayout; 189 190 if($hybridauth) 191 $this->loginByHybridAuth($hybridauth); 192 193 $this->loginForm = new YumUserLogin('login'); 194 195 if(Yum::module()->captchaAfterUnsuccessfulLogins !== false && 196 Yii::app()->user->getState('yum-login-attempts')

Could you help me to understand why I get this error?

Thank you!

AMilkov commented 10 years ago

Check if you did follow exactly all the hybridauth installation steps as they are described here: https://github.com/thyseus/yii-user-management/blob/master/user/docs/hybridauth.txt

leonardoburchi commented 10 years ago

I think I made all correctly.. This is what I did:

1 - configured main.php adding into user array the key "loginType" with value 7 2 - added to main.php the key hybridAuthProviders with value array('Facebook') 3 - copied index.php from folder modules/user/vendors/hybridauth to yii root folder 4 - copied config.php from modules/user/vendors/hybridauth/ to protected/config/ and renamed to hybridauth.php and I also removed all providers except Facebook, where I configured appid and secret code 5 - I setup base_url in configuration file to http://mysite.com/hybridauth.php

Now when I go into login page, I can see the facebook link and when I click it, I get the redirection on facebook but when it come back to my site, I have the error I posted on my previous post. Did you see something wrong in my setup?

Thank you!

AMilkov commented 10 years ago

Is it possible that the user with same email as the one that you are trying to authenticate via Facebook is already present in your users table? If yes, change the email and try again. It's a glitch in YUM.

leonardoburchi commented 10 years ago

Yes it was as you said, the admin user had the same mail I used to auth via Facebook.. I changed the mail of the admin user and now I can see a new record in user table and a new record in profile table, but I get the same error.. :-(