I\'m trying to allow users to login using facebook but my user management is based on sentry as you know if you connect from facebook, you wont need a password unless you ar
I think that when you create the 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 a login for the user without a password.
You probably also want to put something in the password field other than test if you also have a regular non-facebook login.
Also you may have to activate the user depending on what your plans were with that email:
//You could email this to the user from here.
$activationCode = $user->getActivationCode();
//OR just activate immediately.
$user->attemptActivation($activationCode);
I'm looking at doing something similar, and was thinking of using the facebook uid as the password. Would this not work?
Edit: I can confirm the following works 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'll need customize the model sentry uses using this method (http://forums.laravel.io/viewtopic.php?pid=48274#p48274) in order to specify the relationship with profiles