我遵循了使用Laravel创建注册和登录页面的这个教程。
一切都运行得很顺畅,唯一的问题是我无法登录。如果我提供错误的用户名/密码,它会正确地给出错误消息。但是,如果我使用正确的凭据,我会收到以下错误 -
这是我的(默认)csrf函数 -
这是表单操作 -
一切都运行得很顺畅,唯一的问题是我无法登录。如果我提供错误的用户名/密码,它会正确地给出错误消息。但是,如果我使用正确的凭据,我会收到以下错误 -
Illuminate \ Session \ TokenMismatchException
这是我的(默认)csrf函数 -
Route::filter('csrf', function()
{
if (Session::token() != Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
});
这是表单操作 -
{{ Form::open(array('url'=>'signin', 'class'=>'form-signin')) }}
这是我的UsersController的相关部分
public function __construct() {
$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('getDashboard')));
}
public function postSignin() {
if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password')))) {
return Redirect::to('dashboard')->with('message', 'You are now logged in!');
} else {
return Redirect::to('login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
public function getDashboard() {
$this->layout->content = View::make('users.dashboard');
}
dd(Session::token();
和dd(Input::get('_token')
来检查缺少令牌的部分。 - Andreyco<input type="hidden" name="_token" value="{{ csrf_token() }}" />
- captainblack