Facebook使用哨兵登录,用户[email]需要密码,无需提供密码 [英] Facebook Login with Sentry, A password is required for user [email], none given

查看:198
本文介绍了Facebook使用哨兵登录,用户[email]需要密码,无需提供密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图允许用户使用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/ 作为指导

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使用哨兵登录,用户[email]需要密码,无需提供密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆