我现在需要帮助我无法使用 facebook 登录让我们看看我的代码。
$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');
$existing_user = User::whereFBid($uid);
if (empty($existing_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['fbid'] = $uid;
$user['username'] = $me['username'];
$user['access_token'] = $facebook->getAccessToken();
$rsUser = User::registerUser($user);
}
else
{
$user = new User();
$user->fbid = $uid;
Auth::login($user);
}
return Redirect::to('/')->with('message', 'Logged in with Facebook');
我的路线文件
Route::get('/', function()
{
$data = array();
if (Auth::check())
{
$data = Auth::user();
var_dump($data);exit;
}
else
{
echo 'auth check failed';exit;
}
return View::make('hello', array('data'=>$data));
});
我的用户模型已经添加使用 Jenssegers\Mongodb\Model 作为 Eloquent
Auth::login($user) 它通过了,但是当我的代码重定向到 '/' 并且 Auth::check() 它不起作用时会出现其他情况。我该如何解决,有人可以帮忙吗?非常感谢,对不起我的英语。