vendredi 16 octobre 2015

Laravel: blank page after login and then checking for roles

I am using Laravel's native auth module for login and using entrust for user roles.

When user logs in, laravel's native auth module only checks for username/email and password. Then logs the user in. I have put a check if user is logged in with a certain user_type (user_type is also posted) and user has that role, then user is sent to that role's dashboard otherwise user is logged out by Auth::logout and redirected to login page with wrong user_type error.

All code works except when user_type is wrong, then it shows blank login page. I have tried a lot of combinations for redirection but no luck.

My code for logout and redirect is

protected function logoutRedirect(Request $request)
{
    Auth::logout();

    return redirect($this->loginPath())
        ->withInput($request->only($this->loginUsername(), 'remember'))
        ->withErrors([
            $this->loginRole() => $this->getWrongRoleMessage(),
        ]);

    /*
    return view('auth.login')
        ->withInput($request->only($this->loginUsername(), 'remember'))
        ->withErrors($this->getWrongRoleMessage());
    */

    /*
    return redirect('/auth/login')->withErrors([$this->loginRole() => $this->getWrongRoleMessage()]);
    */
}

I have placed all the redirect methods i could try in the above code in form of comments. If you can find the errors or if you can propose a better solution please let me know. I am new at laravel so I would appreciate if you help me solve this beginners problem.

PS: by the way I am using Laravel 5.1 and on localhost (xampp + MS windows 7)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire