I\'m trying to get the sentry package set up in my app correctly.
I can log a user in and out and protect routes but I can\'t seem to get the redirect::intended
The easiest way.
In your Auth filter use the following:
Route::filter('sentryAuth', function()
{
if ( ! Sentry::check())
{
return Redirect::guest(route('login'));
}
});
In your controller:
public function postAuthenticate()
{
try {
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
$user = Sentry::authenticate($credentials, false);
} catch () {
// validation errors
}
//firstly, Laravel will try to redirect intended page.
//if nothing saved in session, it will redirect to home.
//you can use any route instead of home.
return Redirect::intended(route('home'));
}
Done.
Outside of Sentry:
This code can be used with any type of authentication library. You need two things to implement intended redirection:
1.in your auth filter:
Route::filter('auth', function() { if ( ! Sentry::check()) { return Redirect::guest(route('login')); } });
2.After logged in an user:
//firstly, Laravel will try to redirect intended page. //if nothing saved in session, it will redirect to home. //you can use any url instead of '/' return Redirect::intended('/');