2017-09-06 55 views
0

我想檢查天氣電子郵件是否存在或不發送重置密碼鏈接。 爲了使用ajax函數,但它運行ajax之前顯示500內部服務器錯誤。 我knw 500是令牌錯過匹配錯誤,但我需要令牌來檢查電子郵件存在與否。 但我認爲這樣,窗體標記令牌是自動生成的,然後也使用{{csrf_field()}} 但它顯示相同的錯誤500內部服務器。只是幫助如何解決這個問題,我需要手動生成令牌。Laravel 5.2模式彈出忘記密碼顯示500內部服務器運行AJAX功能時出錯

瀏覽:login.blade.php

{!! Form::open(array('url' => '/auth/login', 'class' => 'form- login')) !!} 
    <div class="form-title"> <span class="form-title">Login</span> </div> 
    <div class="form-group"> 
     <label class="control-label visible-ie8 visible-ie9">Username</label> 
     <input class="form-control form-control-solid placeholder-no-fix required" type="text" autocomplete="off" placeholder="Email" name="email" /> 
     </div> 

     <div class="form-group"> 
     <label class="control-label visible-ie8 visible-ie9">Password</label> 
     <input class="form-control form-control-solid placeholder-no-fix passwordclass required" type="password" autocomplete="off" placeholder="Password" name="password" /> 
     </div> 

    <div class="form-actions"> 
     <button type="submit" class="btn red btn-block uppercase clicklogin" style="background-color:#d5ed31 !important;border-radius:4px !important;border:1px solid #ddd;">Login</button> 
    </div> 


    <div class="form-actions"> 
     <div class="pull-left"> 
     <label class="rememberme mt-checkbox mt-checkbox-outline"> 
     <input type="checkbox" name="remember" value="1" /> 
      Remember me <span></span> </label> 
     </div> 

    <div class="pull-right forget-password-block"> <a class="btn-link" data-target="#modalforget" data-toggle="modal">Forgot Password? </a></div> 
    </div> 

    {!! Form::close() !!} 

    <!-- END LOGIN FORM --> 






    <!-- BEGIN FORGOT PASSWORD FORM--> 
    {!! Form::open(array('url'=>'password/reset','class' => 'form-horizontal create_forget_form','method'=>'POST', 'id' =>'forgetdata', 'files' => true)) !!} 

    {{ csrf_field() }} 


    <div class="modal fade" id="modalforget" tabindex="-1" data-width="760px" > 
    <div class="modal-dialog" style="width:760px !important;"> 
    <div class="modal-content" style="background-color:#26344b;padding:20px;border-radius:12px !important;"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button> 
      <div class="form-title"> <span class="form-title">Forget Password</span> </div> 
     </div> 
     <div class="modal-body" style="height:auto !important;"> 
      <div class="row"> 
      <div class="col-md-12"> 
       <div class="form-group"> 
        <strong style="color: #ffffec; font-size: large; ">&nbsp; &nbsp; &nbsp; &nbsp; Please enter your email. A password reset link will be sent to this email.</strong> 
        </div> 
       </div> 
      </div> 
      <div class="row"></div> 
      <div class="row"> 
      <div class="col-md-10"> 
       <div class="form-group"> 
       <div class="col-md-2"></div> 
       <div class="col-md-10"> 
       <input class="form-control required" type="email" autocomplete="off" placeholder="Email" id="forget_email" name="forget_email"style="font-size: large;" /> 
         <span class="my-error-class" id="email_status"></span> 
       </div> 
       </div> 
      </div> 
      </div> 
     <div class="modal-footer"> 
      <button type="button" value="Submit" id="submitButton" class="btn green">Submit</button> 
      <button type="button" value="Cancel" class="btn default red" data-dismiss="modal">Cancel</button> 
      <button type="reset" value="Clear" class="btn blue">Clear</button> 
     </div> 
     </div> 
     </div> 
     </div> 
    </div> 
</form> 

的Ajax功能login.blade.php

<script type="text/javascript"> 
$('#submitButton').click(function(){ 
    var formdata=new FormData($(this)[0]); 
    $.ajax({ 
     url:"{{ URL::to('password/reset') }}", 
     type: 'POST', 
     data: formdata, 
     async: false, 
     cache: false, 
     contentType: false, 
     processData: false, 
     context:this, 
     dataType: "json", 
     success: function (returndata) 
     { 
       if(returndata == 0) 
      { 
       $('#email_status').html('This Email does not Exists'); 
       return false; 

      } 
      else 
      { 
       $('#email_status').html(""); 
       return false; 
      } 
     }, 
     error: function(data) 
     { 
      console.log(data); 
     } 
    }); 
}); 
</script> 

路線文件:

Route::group(['middleware' => 'auth'], function() 
{ 
    Route::post('password/reset','Auth\[email protected]'); 
} 

控制器驗證\ AuthController 2 R esetPassword:

public function resetPassword() 
    { 
    $email =Input::get('forget_email'); 
    $user_email = DB::table('users')->where('email', $email)->whereNull('deleted_at')->first(); 
    if($user_email) 
    { 
     return '1'; 
    } 
    else 
    { 
     return '0'; 
    } 

} 

Screen Shot Of Error

回答

1

我認爲你必須寫外面auth組路線。

Route::post('password/reset','Auth\[email protected]'); 
+0

我試過但是同樣的錯誤 – ratnesh

+0

@ratnesh,把你的函數名改爲駱駝大小寫。 'Resetpassword'並且在路由中改變它。這可能是問題。 –

+0

這是問題@ratnesh? –

0

問題是您正在使用POST要求與ajax和每一個崗位請求你與像請求傳遞csrf-token

headers: { 
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') 
}, 

在你的Ajax代碼將這個一切都會精細。

或者,如果你想從CSRF驗證排除的特定URI,去project/app/Http/Middleware,有一個文件VerifyCsrfToken.php其放置在路線清單:這裏定義

protected $except = [ 
    // route list here 
]; 

所有航線不包括從csrf-token檢查。

+0

Actully我已經寫在腳本標記$ .ajaxSetup上面{{0}名稱:{X-CSRF-TOKEN':$('meta [name =「csrf-token」]')。attr ('content') } }); – ratnesh

+0

發佈您正在收到的確切錯誤消息? –

+0

POST http:// localhost/selfcomply/public/password/reset 422(Unprocessable Entity) – ratnesh