2016-08-03 72 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。