I am using same method for get and post request of login authentication like
public function login()
{
if (Request::isMethod('post')){
// Getting credentials
$username = Input::get('username');
$password = Input::get('password');
// Authenticating super admin
if(Auth::attempt(array('email'=>$username,'password'=>$password,'sysadmin'=>1))){
return Redirect::To('superadmin');
}else{
Session::flash('message', 'Invalid Credentials !');
return View::make('superadmin::login');
}
}else{
echo View::make('superadmin::login');
}
}
This is the code of login view to display error messages:
@if(Session::has('message'))
<div class="alert-box message">
<h2>{{ Session::get('message') }}</h2>
</div>
@endif
The problem is when i enter invalid credentials while login, then error message is displayed at the form but after that on manually refreshing the login page, session message does not disappear. Where as, on second time page refresh, session message disappears.
I know that this is happening because URL (referrer) remain same in my case because same method "login" is being used for both types of request (get and post).
What would be the best way to display error messages in this case so that on page refresh or automatically the message should disappear.
This is an old question but I want to explain the easiest way:
@if(Session::has('message'))
<div class="alert-box message">
<h2>{{ Session::pull('message') }}</h2>
</div>
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With