Question

is it somehow possible to redirect a user, after the auth, to the second to last page?

Why?
I open the Login in an overlay. When the validation throws an error, the Redirect is:

return Redirect::intended('?openOverlay=login')->with('error-login-noconfirm','1');  

When the user enters the right logindata, the Redirect is back(), which means, he will be redirected to the right page BUT with the open Overlay.

I need to get rid of the overlay when the user logs in successfully, means, I maybe need to pass the route to the login method, or something like that.

Do you have an idea? Thanks!

EDIT:
Login code:

    if ($validator->fails()) {
        return Redirect::intended('?openOverlay=login')
            ->withErrors($validator)
            ->withInput(Input::except('password'));
    } else {
        $user = User::where('email', Input::get('email'))->first();

        if (Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'), 'confirmed' => 1))) {
            return Redirect::intended();
        } else {
            return Redirect::intended('?openOverlay=login')->with('error-login-noconfirm','1');
        }
    }

intended isn't working too. It redirects me to my / pages instead of the "last" page.

Was it helpful?

Solution

You don't have to use back(). Login process works this way:

1) A 'still not logged' user try to browse your site and hit a route:

Route::get('dashboard', 'DashboardController@dashboard');

2) But is redirected to the login form:

return Redirect::to('?openOverlay=login');

3) After a successful login you have to use Redirect::intended() to redirect your user to the url he/she first tried to access:

if (Auth::attempt(array('email' => $email, 'password' => $password)))
{
    // Login succeeded, redirect it to the intended url

    return Redirect::intended('home');
}
else
{
    /// Login failed, redirect back to login, so your user can try to login again

    return Redirect::back()->with('error-login-noconfirm','1');
}

Your user will be redirected to 'dashboard' and the 'home' is a fallback route, just in case something happened to the session and there is no more intended ('dashboard') url on it.

If the intended url is not the first one accessed, you can change it in Session:

$path = Session::put('url.intended', $the_actual_url_intended);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top