有人请帮助我。我正在尝试实现社交网络身份验证,一切正常,但Auth
下的路由不起作用。他们重定向回登录页面。我的Auth
或路由有什么问题。我的路由和控制器文件位于
Route::group(['middleware' => ['web']], function () {
Route::get('facebook',array(
'as' => 'facebook',
'uses' =>'FacebookController@redirectToProvider'
));
Route::get('Callback', 'FacebookController@handleProviderCallback');
});
Route::group(['middleware' => ['web','auth']], function () {
Route::get('play', function () {
return view('landing');
});
Route::get('go', function () {
return view('landing');
});
});
控制器
public function handleProviderCallback()
{
try
{
$user = Socialize::with('facebook')->user();
}
catch (Exception $e)
{
return Redirect::to('login');
}
$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);
$user = Auth::user();
return Redirect::to('play');
}
private function findOrCreateUser($facebookUser)
{
if ($authUser = User::where('id', $facebookUser->getId())->first())
{
return $authUser;
}
return User::create([
'id' => $facebookUser->getId(),
'name' => $facebookUser->getName(),
'email' => $facebookUser->getEmail(),
'gender' => $facebookUser->user['gender'],
'avatar' => $facebookUser->getAvatar(),
'avatar_original' => $facebookUser->avatar_original,
'verified' => $facebookUser->user['verified']
]);
}