我正在尝试允许用户使用 facebook 登录,但我的用户管理基于哨兵如您所知,如果您从 facebook 连接,除非您正常创建帐户,否则您不需要密码.有没有办法告诉哨兵(http://docs.cartalyst.com/sentry-2/installation/laravel-4)这是一个 facebook 登录,它不需要密码"
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 are creating a account normally. Is there a way to tell sentry(http://docs.cartalyst.com/sentry-2/installation/laravel-4) that this is a facebook login and it doesnt require a "password"
我尝试给帐户一个临时密码,但我收到了没有为用户提供散列器,即使我散列它.
I tried giving the account a temp password but i receive A hasher has not been provided for the user , even when i hash it.
对此有何建议?
我也在使用 http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/ 作为指南
I'm also using 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');
});
我正在考虑做类似的事情,并且正在考虑使用 facebook uid 作为密码.这不行吗?
I'm looking at doing something similar, and was thinking of using the facebook uid as the password. Would this not work?
我可以为我确认以下工作:
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');
}
另请注意,您需要使用此方法自定义哨兵使用的模型 (http://forums.laravel.io/viewtopic.php?pid=48274#p48274) 以指定与配置文件的关系
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
这篇关于Facebook 使用 Sentry 登录,用户 [email] 需要密码,没有给出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!