我使用相同的方法来获取和发布登录认证请求
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');
}
}
这是显示错误消息的登录视图代码:
@if(Session::has('message'))
<div class="alert-box message">
<h2>{{ Session::get('message') }}</h2>
</div>
@endif
问题是当我在登录时输入无效凭据时,表单上会显示错误消息,但在手动刷新登录页面之后,会话消息不会消失.在第二次页面刷新时,会话消息消失.
我知道这种情况正在发生,因为URL(referrer)在我的情况下保持相同,因为同样的方法“login”被用于两种类型的请求(get和post).
在这种情况下,显示错误消息的最佳方法是什么,以便在页面刷新或自动消息消失.
解决方法:
这不是一个合适的人吗?
return View::make('superadmin::login')->with('message', 'Invalid credentials');
然后在你看来:
@if($message)
<div class="alert-box message">
<h2>{{ $message }}</h2>
</div>
@endif
这是因为你不需要闪光,因为闪光后你永远不会使用重定向.
原文地址:https://codeday.me/bug/20190830/1770195.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。