Logging into Facebook using Sentry, a password is required for the user [email].

I’m trying to allow users to log in using facebook, but my user management is based on the time as you know, if you connect from facebook you don’t need a password unless you usually create an account. Is there a way to tell the sentry ( http://docs.cartalyst.com/sentry-2/installation/laravel-4 ) that this is a facebook login and it does not require a “password”

I tried to give the account a temporary password, but I get the hasher was not provided for the user, even when I had his hash.

Any advice on this?

I also use http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/ as a guide

Route::get('login/fb/callback', function() { $code = Input::get('code'); if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook'); $facebook = new Facebook(Config::get('facebook')); $uid = $facebook->getUser(); if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error'); $me = $facebook->api('/me'); $profile = Profile::whereUid($uid)->first(); if (empty($profile)) { $user = new User; $user->name = $me['first_name'].' '.$me['last_name']; $user->email = $me['email']; $user->photo = 'https://graph.facebook.com/'.$me['username'].'/picture?type=large'; $user->save(); $profile = new Profile(); $profile->uid = $uid; $profile->username = $me['username']; $profile = $user->profiles()->save($profile); } $profile->access_token = $facebook->getAccessToken(); $profile->save(); $user = $profile->user; Auth::login($user); return Redirect::to('/')->with('message', 'Logged in with Facebook'); 

});

+4
source share
2 answers

I look at something similar, and was thinking about how to use facebook uid as a password. Would it work?

Edit: I can confirm the following work for me:

 function callback() { $code = Input::get('code'); if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook'); $facebook = new Facebook(Config::get('facebook')); $uid = $facebook->getUser(); if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error'); $me = $facebook->api('/me'); //dd($me); //Check if user profile exists $profile = Profile::whereUid($uid)->first(); if (empty($profile)) { // Create the user $user = Sentry::createUser(array( 'email' => $me['email'], 'password' => $uid, 'first_name' => $me['first_name'], 'last_name' => $me['last_name'], 'photo' => 'https://graph.facebook.com/'.$me['username'].'/picture?type=large', 'activated' => 1 )); // Find the group using the group id $registered = Sentry::findGroupById(2); // Assign the group to the user $user->addGroup($registered); $profile = new Profile(); $profile->uid = $uid; $profile->username = $me['username']; $profile = $user->profiles()->save($profile); } $profile->access_token = $facebook->getAccessToken(); $profile->save(); $user = $profile->user; Sentry::login($user, false); $user = Sentry::getUser(); echo $user->first_name . " logged in."; //return Redirect::to('/')->with('message', 'Logged in with Facebook'); } 

Also note that you will need to configure the hourly use of the model using this method ( http://forums.laravel.io/viewtopic.php?pid=48274#p48274 ) to indicate the connection with profiles

+1
source

I think that when you create a user, you need to use Sentry :: createUser ()

 $user = Sentry::createUser(array( 'name' => $me['first_name'].' '.$me['last_name'], 'email' => $me['email'], 'password' => 'test', 'photo' => 'https://graph.facebook.com/'.$me['username'].'/picture?type=large', )); 

And then use Sentry :: login ($ user, false); to force logon for a user without a password.

You probably also want to put something in the password field other than the test, if you also have regular login without facebook.

You may also need to activate the user depending on your plans with this email address:

 //You could email this to the user from here. $activationCode = $user->getActivationCode(); //OR just activate immediately. $user->attemptActivation($activationCode); 
+3
source

Source: https://habr.com/ru/post/1501880/


All Articles