登录时令牌不匹配异常(Laravel) [英] Token Mismatch Exception on Login (Laravel)

查看:64
本文介绍了登录时令牌不匹配异常(Laravel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照教程创建了Laravel注册和登录页面.

I followed this tutorial on creating a registration and login page using Laravel.

一切正常,唯一的问题是我无法登录.如果我提供了错误的用户名/密码,它会正确地给我一条错误消息.但是,如果我使用正确的凭据,则会收到以下错误-

Everything works smoothly, the only issue is that I am unable to Login. If I provide the wrong username/password, it correctly gives me an error message. But if I use the right credentials, I get the following error -

Illuminate \ Session \ TokenMismatchException

这是我的(默认)csrf函数-

This is my (default) csrf function -

Route::filter('csrf', function()
{
    if (Session::token() != Input::get('_token'))
    {
        throw new Illuminate\Session\TokenMismatchException;
    }
});

这是表单操作-

{{ Form::open(array('url'=>'signin', 'class'=>'form-signin')) }}

这是我的UsersController的相关部分

And this is the relevant portion of my 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');
}

推荐答案

Laravel对会话进行了深奥的使用,并且由于某种原因(例如,当您重新设置您的用户表),您会得到令牌不匹配异常,而无需进一步说明.

Laravel makes a quite esoteric use of sessions, and when the user cookie and the user salt in stored in the database disalign for some reason (for example, when you re-seed your user table), you get a Token Mismatch Exception without further explanation.

如果是这种情况,只需删除您的cookie.

If that's the case, just delete your cookies.

这篇关于登录时令牌不匹配异常(Laravel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆