【发布时间】:2014-03-06 20:52:39
【问题描述】:
我正在一个新应用程序中使用 Laravel 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