2016-08-03 73 views
0

我一直试图把我的头围绕这一段现在,但似乎无法弄清楚问题是什么。我已经在Laravel 5.2。*中手动创建了一个登录页面,这是我过去成功完成的,但由于某种原因,这次它不工作......下面是我的代码的重要部分的细目:postLogin显示令牌,似乎并没有在Laravel 5.2中调用

Route::group(['middleware' => ['web']], function() { 
    // Authentication Routes... 
    Route::get('auth/login', 'Auth\[email protected]'); 
    Route::post('auth/login', 'Auth\[email protected]'); 
    Route::get('auth/logout', 'Auth\[email protected]'); 
    .... 
}); 

<!DOCTYPE html> 

<html lang="en"> 
    <head> 
     <meta name="csrf-token" content="{{ csrf_token() }}" /> 
     .... 
    </head> 
    <body> 
     <form action="{{ url('/auth/login') }}" class="clearfix" id="login" method="post" novalidate> 
      {!! csrf_field() !!} 

      @if (count($errors) > 0) 
       <div class="show validation-summary"> 
        <strong>Whoops!</strong> There were some problems with your input.<br /> 
        <ul> 
         @foreach ($errors->all() as $error) 
          <li>{{ $error }}</li> 
         @endforeach 
        </ul> 
       </div> 
      @else 
       <div class="validation-summary"> 
        <ul> 
        </ul> 
       </div> 
      @endif 

      <label class="grey" for="email"><b>Username: </b></label> 
      <input class="field" type="text" name="email" id="email" value="{{ old('email') }}" size="23" /> 
      <label class="grey" for="password"><b>Password:</b></label> 
      <input class="field" type="password" name="password" id="password" size="23" /> 
      <button class="bt_login" name="submit" type="submit"> 
       <i class="fa fa-btn fa-sign-in"></i> Login 
      </button> 
     </form> 
     .... 
    </body> 
</html> 

下面是从AuthenticatesUsers性状postLogin方法:

public function postLogin(Request $request) 
{ 
    return $this->login($request); 
} 

public function login(Request $request) 
{ 
    $this->validate($request, [ 
     $this->loginUsername() => 'required', 'password' => 'required', 
    ]); 

    // If the class is using the ThrottlesLogins trait, we can automatically throttle 
    // the login attempts for this application. We'll key this by the username and 
    // the IP address of the client making these requests into this application. 
    $throttles = $this->isUsingThrottlesLoginsTrait(); 

    if ($throttles && $this->hasTooManyLoginAttempts($request)) { 
     return $this->sendLockoutResponse($request); 
    } 

    $credentials = $this->getCredentials($request); 

    if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) { 
     return $this->handleUserWasAuthenticated($request, $throttles); 
    } 

    // If the login attempt was unsuccessful we will increment the number of attempts 
    // to login and redirect the user back to the login form. Of course, when this 
    // user surpasses their maximum number of attempts they will get locked out. 
    if ($throttles) { 
     $this->incrementLoginAttempts($request); 
    } 

    return $this->sendFailedLoginResponse($request); 
} 

当登录按钮点击它似乎显示CSRF令牌值,甚至不打在AuthenticatesUsers性状postLogin方法。如果你想要一个实例,你可以去http://www.dorothea.co.za/auth/login并点击屏幕顶部的登录滑动面板,然后点击登录。

+0

你可以发布你的'Auth \ AuthController @ postLogin'方法/ – jaysingkar

+0

@ jaysingkar我的postLogin方法只是来自AuthenticatesUsers特征的默认值,我会更新我的文章以包含此信息。 –

+0

你确定你还没有忘记一些回应用于调试的地方?这真的很奇怪,它不能只输出令牌和死亡。 – TheFallen

回答

0

为了回答我上面的问题,问题出现在app/Http/Middleware/VerifyCsrfToken.php类的tokensMatch方法中。下面是这是导致该问题的代码:

echo($request->header('X-CSRF-Token') .' '. $request->input('_token')); 
die(); 

我不认为我做了这个文件进行任何更改所以要知道,如果你使用的身份验证,并且laravel的版本是5.2.7。