我需要帮助,现在我不能登录与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));
});我的用户模型已经添加了use Jenssegers\Mongodb\Model as Eloquent
Auth::login($user)它是pass,但是当我的代码重定向到'/‘和Auth::check()时,它就不工作了,它将进入else条件。我该怎么解决这个问题,任何人都能帮上忙吗?非常感谢,对我的英语表示抱歉。
发布于 2014-01-07 23:33:47
在else语句中,您重新实例化了用户,但这对我来说没有任何意义。在if语句之前,您要尝试查找用户。然后是if语句,用于当用户不存在时使用。然后是else语句,用于当用户确实存在的时候。因此,您不必创建新的用户模型:
else
{
$user = new User();
$user->fbid = $uid;
Auth::login($user);
}但是您必须使用$existing_user变量才能登录。
else
{
Auth::login($existing_user);
}https://stackoverflow.com/questions/20943729
复制相似问题