我在Laravel 5.1中的密码重置过程中遇到了一些问题
生产步骤:
- 忘记密码页面(输入密码,重置链接将通过电子邮件发送)
- 从电子邮件中,用户将单击类似于 http://domain.com/password/reset/{longtoken}的链接 将显示一个表单,输入新密码并重新输入密码
在那个表格中,我使用了相同的表格 https://laravel.com/docs/5.1/authentication#resetting-passwords 在这里给出"示例密码重置表格"
我刚刚注意到隐藏的电子邮件字段没有填充
<input type="email" name="email" value="{{ old('email') }}">
当我使用拉拉维尔的默认方法时,它调用 -
public function getReset($token = null)
{
if (is_null($token)) {
throw new NotFoundHttpException;
}
return view('auth.reset')->with('token', $token);
}
显然,没有电子邮件变量被传递到视图,并且在提交后命中postReset
-
public function postReset(Request $request)
{
$this->validate($request, [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
]);
$credentials = $request->only(
'email', 'password', 'password_confirmation', 'token'
);
$response = Password::reset($credentials, function ($user, $password) {
$this->resetPassword($user, $password);
});
switch ($response) {
case Password::PASSWORD_RESET:
return redirect($this->redirectPath())->with('status', trans($response));
default:
return redirect()->back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
}
}
所以主要问题是当我使用 laravel 5.1 文档中的默认指南时,电子邮件字段没有填充。
我应该像令牌一样传递电子邮件参数还是我错过了什么?
只需在模型 User.php
中添加以下代码
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token.'/'.$this->email));
}