2014-09-25 73 views
0

對laravel密碼提醒有疑問。Laravel密碼提醒

  1. 我可以得到RemindersController控制器通過電子郵件從postRemind方法的鏈接。

  2. 當我點擊復位郵件鏈路上(http://localhost/projects/mylaravelproject/public/password/reset/d3f0480aa46baa4a8ae23770509b1dc6b6ca3cbf

我得到這個錯誤:的Symfony \元器件\ HttpKernel \異常\ NotFoundHttpException

  • 作爲結論,我在嘗試達到reset.blade頁時遇到問題。

    <form action="{{ action('[email protected]') }}" method="POST"> 
        <input type="hidden" name="token" value="{{ $token }}"> 
        <input type="email" name="email"> 
        <input type="password" name="password"> 
        <input type="password" name="password_confirmation"> 
        <input type="submit" value="Reset Password"> 
    </form> 
    
  • 4. This is the whoops preview

  • 這是我的routes.php文件的文件:
  • Route::get('/', function() 
    { 
        return View::make('pages.home'); 
    }); 
    
    //routes to home page when an inner call incomes from the main menu 
    Route::get('home', [ 
         'as' => 'home', 
         function(){ 
          return View::make('pages.home'); 
         } 
    ]); 
    
    //routes to about page 
    Route::get('about', [ 
         'as' => 'about', 
         function(){ 
          return View::make('pages.about'); 
         } 
    ]); 
    
    //routes to login page 
    Route::any('login', [ 
         'as' => 'login', 
         function(){ 
          return View::make('pages.login'); 
         } 
    ]); 
    
    //Routes to forgot password page 
    Route::any('remindPassword', [ 
         'as' => 'password.remind', 
         function(){ 
          return View::make('password.remind'); 
         } 
    ]); 
    
    //Forgot Password Post Controller 
    Route::post('password.remind', [ 
         'uses' => '[email protected]', 
         'as' => 'password.remind.postRemind' 
    ]); 
    
    //Routes to register page 
    Route::any('register', [ 
         'as' => 'register', 
         function(){ 
          return View::make('pages.register'); 
         } 
    ]); 
    
    //Registration Post Controller 
    Route::post('register', array(
        'uses' => '[email protected]', 
        'as' => 'registration.store' 
    )); 
    
    Route::post('login', array(
        'uses' => '[email protected]', 
        'as' => 'session.store' 
    )); 
    Route::get('logout', array(
        'uses' => '[email protected]', 
        'as' => 'session.destroy' 
    )); 
    

    在此先感謝。

    +0

    您是否將'password/reset/{token}'路線映射到提醒控制器的正確方法? – Luceos 2014-09-25 07:13:37

    +0

    RemindersController中的getReset方法有一個令牌和路由,如果我沒有錯的話。像這樣在getReset方法中,我有這樣一行:返回View :: make('password.reset') - > with('token',$ token);我有這個網頁下的意見/密碼/提醒 – 2014-09-25 07:22:37

    +0

    在你的HTML嘗試而不是行動'route('password.remind.postRemind')' – Luceos 2014-09-25 07:50:22

    回答

    1

    我已經嘗試michaelcurry的答案,但仍然沒有爲我工作,但謝謝大家給我關於改進我的代碼的想法。現在,它是工作,這裏是代碼:

    reset.blade頁路徑查看/密碼/重置

    <form action="{{ action('[email protected]') }}" method="POST"> 
        <input type="hidden" name="token" value="{{ $token }}"> 
        Email<input type="email" name="email"> 
        Password<input type="password" name="password"> 
        Password<input type="password" name="password_confirmation"> 
        <input type="submit" value="Reset Password"> 
    </form> 
    

    這是我應該在路線。PHP

    //Reset Password Get Controller 
    Route::get('password/reset/{hash}', array(
        'uses' => '[email protected]', 
        'as' => 'password.reset', 
    )); 
    
    //Reset Password Post Controller 
    Route::post('password/reset/', [ 
         'as' => 'password/reset', 
         'uses' => '[email protected]' 
    ]); 
    

    最後,這是自動生成的,但編輯RemindersController控制器。

    <?php 
    
    class RemindersController extends Controller { 
    
        /** 
        * Display the password reminder view. 
        * 
        * @return Response 
        */ 
        public function getRemind() 
        { 
         return View::make('password.remind'); 
        } 
    
        /** 
        * Handle a POST request to remind a user of their password. 
        * 
        * @return Response 
        */ 
        public function postRemind() 
        {   
         switch ($response = Password::remind(Input::only('email'))) 
         { 
          case Password::INVALID_USER: 
           return Redirect::back()->with('error', Lang::get($response)); 
    
          case Password::REMINDER_SENT: 
           return Redirect::back()->with('status', Lang::get($response)); 
         } 
        } 
    
        /** 
        * Display the password reset view for the given token. 
        * 
        * @param string $token 
        * @return Response 
        */ 
        public function getReset($token = null) 
        { 
         if (is_null($token)) App::abort(404); 
    
         return View::make('password.reset')->with('token', $token); 
        } 
    
        /** 
        * Handle a POST request to reset a user's password. 
        * 
        * @return Response 
        */ 
        public function postReset() 
        { 
         $credentials = Input::only(
          'email', 'password', 'password_confirmation', 'token' 
         ); 
    
         $response = Password::reset($credentials, function($user, $password) 
         { 
          $user->password = Hash::make($password); 
    
          $user->save(); 
         }); 
    
         switch ($response) 
         { 
          case Password::INVALID_PASSWORD: 
          case Password::INVALID_TOKEN: 
          case Password::INVALID_USER: 
           return Redirect::back()->with('error', Lang::get($response)); 
    
          case Password::PASSWORD_RESET: 
           return Redirect::to('/'); 
         } 
        } 
    } 
    

    最後,感謝您的反饋和耐心。

    1

    該錯誤通常意味着您的路線有問題。請粘貼堆棧跟蹤,甚至拍攝Whoops屏幕的屏幕截圖,以進一步瞭解這一點。

    而且,讓我們知道(這條路在你的路線文件夾)

    ,因爲我去,我會更新這個響應的路由。

    - 更新 -

    你必須routes.php文件的實際路徑

    Route::post('password/reset/{hash}', ['as' => 'password.reset', 'uses' => '[email protected]']); 
    

    然後,你需要發佈到這條路線

    <form action="{{ route('password.reset', $hash) }}" method="POST"> 
    

    $哈希是這樣的實例將是您的URL的最後一部分「d3f0480aa46baa4a8ae23770509b1dc6b6ca3cbf」我假設這是您的密碼重置令牌

    +0

    我分享了whoops screen和routes.php文件。 – 2014-09-25 07:48:22