Laravel密码提醒

时间:2014-09-25 07:12:28

标签: php laravel

有关laravel密码提醒的问题。

  1. 我可以通过 RemindersController 控制器中的 postRemind 方法通过电子邮件获取该链接。

  2. 当我点击重置邮件链接(http://localhost/projects/mylaravelproject/public/password/reset/d3f0480aa46baa4a8ae23770509b1dc6b6ca3cbf

  3. 我收到此错误: Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

    1. 结论是,我在尝试访问 reset.blade 页面时遇到了问题。

      <form action="{{ action('RemindersController@postReset') }}" 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>
      
    2. 4。This is the whoops preview

      1. 这是我的routes.php文件:
      2. 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' => 'RemindersController@postRemind',
                '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' => 'RegistrationController@store',
            'as' => 'registration.store'
        ));
        
        Route::post('login', array(
          'uses' => 'SessionController@store',
          'as' => 'session.store'
        ));
        Route::get('logout', array(
          'uses' => 'SessionController@destroy',
          'as' => 'session.destroy'
        ));
        

        提前致谢。

2 个答案:

答案 0 :(得分:1)

该错误通常表示您的路线存在问题。请粘贴堆栈轨道甚至拍摄Whoops屏幕的屏幕截图以进一步查看此内容。

另外,让我们知道路线(在此路线的路线文件夹中)

我会随时更新此回复。

- 更新 -

您需要在routes.php

中拥有实际路线
Route::post('password/reset/{hash}', ['as' => 'password.reset', 'uses' => 'RemindersController@postReset']);

然后你需要发布到那条路线

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

$ hash这个实例将是你网址的最后一部分“d3f0480aa46baa4a8ae23770509b1dc6b6ca3cbf”我假设这是你的密码重置令牌

答案 1 :(得分:1)

我已经尝试了michaelcurry的答案,但仍然没有为我工作,但是感谢大家给我提出改进我的代码的想法。现在它正在运行,这里是代码:

路径视图/密码/重置上的 reset.blade 页面:

<form action="{{ action('RemindersController@postReset') }}" 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>

这就是我应该在 routes.php

中拥有的内容
//Reset Password Get Controller
Route::get('password/reset/{hash}', array(
    'uses' => 'RemindersController@getReset',
    'as' => 'password.reset',
));

//Reset Password Post Controller
Route::post('password/reset/', [
        'as' => 'password/reset',
        'uses' => 'RemindersController@postReset'
]);

最后,这是自动生成但已编辑的 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('/');
        }
    }
}

最后,感谢您的反馈和耐心。