2014-09-25 76 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