【问题标题】:Laravel 4 Authentication: Reminders Controller - GET reset not foundLaravel 4 身份验证:提醒控制器 - 未找到 GET 重置
【发布时间】:2014-03-06 20:52:39
【问题描述】:

我正在一个新应用程序中使用 Laravel 4 的内置密码提醒功能。似乎它生成的代码和文档所说的要么不完整、不一致,要么我错过了一个关键点。

到目前为止,我已经...

  1. 已创建提醒表
  2. 已迁移
  3. 已创建提醒控制器
  4. 成功测试了password/remind 的get/post。

我被卡住的地方是控制器的重置方法。提醒 url 成功发送到我的电子邮件,一旦我点击它,我就会收到 Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 错误。

Password::remind 静态方法发送到我的电子邮件的 url 是http://localhost/application/public/password/reset/3e5e7a5c8562b28909b9948e848c5692dccb4f8a

我在提醒控制器中的 GET / POST 重置方法 -

    public function getReset($token = null)
    {
        if (is_null($token)) App::abort(404);

        return View::make('password.reset')->with('token', $token);
    }

    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('/');
        }
    }

我的密码/reset.blade.php 文件 -

{{ Form::open(array('url' => 'password/reset')) }}
  {{ Form::hidden('token', $token) }}
  {{ Form::email('email', null, array('class'=>'', 'placeholder'=>'Email Address')) }}
  {{ Form::password('password', array('class'=>'', 'placeholder'=>'Password')) }}
  {{ Form::password('password_confirmation', array('class'=>'', 'placeholder'=>'Password Confirmation')) }}

  {{ Form::submit('Reset Password', array('class'=>'')) }}
{{ Form::close() }}

有人知道我哪里出错了吗?

【问题讨论】:

  • 你的路线是什么,Route::get('password/reset/{token}') 存在吗?
  • Sans {token},是的。大概就是这样。文档没有暗示这一点,但我现在明白这是如何隐含的。当我回到我的机器时让我测试一下。想要发布它作为答案,如果这实际上解决了它?

标签: php symfony authentication laravel laravel-4


【解决方案1】:

如果它们不存在,您最有可能错过的一些路线添加这些。

Route::get('password/reset/{token}', 'RemindersController@getReset');

您也可能需要重置post 路由。

Route::post('password/reset/{token}', 'RemindersController@postReset');

【讨论】:

  • 我错过了 {token}!非常感谢,凯尔
  • @CasBloem 没有问题,只是因为它与您解决问题的方法不同。您还应该检查它的发布日期,因为框架在 9 个月内发生了很大变化。
  • 我错过了什么吗? @CasBloem 是谁?
  • @Seth 他评论说这个答案是错误的,但现在他似乎改变了主意。
猜你喜欢
  • 1970-01-01
  • 2018-10-28
  • 2013-09-09
  • 1970-01-01
  • 1970-01-01
  • 2017-01-04
  • 1970-01-01
  • 1970-01-01
  • 2013-06-16
相关资源
最近更新 更多