php - 使用 Sentry 登录 Facebook,用户 [email] 需要密码,没有给出

标签 php html facebook facebook-php-sdk laravel-4

我试图让用户使用 facebook 登录,但我的用户管理是基于 sentry 如您所知,如果您从 Facebook 连接,除非您正常创建帐户,否则不需要密码。有没有办法告诉哨兵(http://docs.cartalyst.com/sentry-2/installation/laravel-4)这是一个 facebook 登录并且不需要“密码”

我尝试为该帐户提供一个临时密码,但我收到了 没有为用户提供哈希器,即使我对其进行哈希处理也是如此。

对此有什么建议吗?

我也在使用 http://maxoffsky.com/code-blog/integrating-facebook-login-into-laravel-application/作为向导

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

});

最佳答案

我认为当你创建用户时你需要使用 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',
));

然后使用 Sentry::login($user, false); 强制用户在没有密码的情况下登录。

如果您也有常规的非 Facebook 登录,您可能还想在密码字段中输入一些东西,而不是测试。

此外,您可能必须激活用户,具体取决于您对该电子邮件的计划:

//You could email this to the user from here.
$activationCode = $user->getActivationCode();

//OR just activate immediately. 
$user->attemptActivation($activationCode);

关于php - 使用 Sentry 登录 Facebook,用户 [email] 需要密码,没有给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18768103/

相关文章:

php - MySQL 错误,连接时表/别名不唯一

php - 我的数据库中的 while 循环正在重复结果。我知道这是我的查询格式不正确。

php - 如何从两个数组创建关联数组?

css - 显示内容的三 Angular 形

html - 获得焦点时为父元素应用样式

html - 在 div 中垂直居中文本

php - 使用 PHPExcel 处理 .xls 获取 OOM

Facebook 无法识别 Netlify 上的一些 Gatsby React Helmet 元标签

facebook - 如何检查用户是否喜欢某个网址

ios - 使用 FBSDKShareLink 在 Facebook 上共享链接时停止 fb.me 作为 contentTitle?