I'm having some issues with password reset process in Laravel 5.1
Step to produce:
- Forget password page (Enter password and a reset link will be sent as email)
- From email user will click a link similar to http://domain.com/password/reset/{longtoken} A form will shown enter new password and retype password
In that form i used same form give here https://laravel.com/docs/5.1/authentication#resetting-passwords "Sample Password Reset Form"
I just noticed that hidden email field is not populating
<input type="email" name="email" value="{{ old('email') }}">
As i am using laravel's default methods it calls -
public function getReset($token = null)
{
if (is_null($token)) {
throw new NotFoundHttpException;
}
return view('auth.reset')->with('token', $token);
}
Clearly there is no email variable which is passed to view and it hits postReset
after submit -
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)]);
}
}
So main problem is email field isn't populating while i am using the default guide from laravel 5.1 documentation.
Should i pass email parameter like token or i am missing something?
old()
is only to retrieve previously typed value after redirection when usingwithInput()
. – Robo RobokAuth\PasswordController@postReset
and there is 'email' => 'required|email' i am also wondering email should not supposed to be passed. If you kindly look at documentation you will see laravel.com/docs/5.1/authentication#resetting-passwords – HADIpostReset
, but only when you type it on your own.old()
has nothing to do with that. You just need a<form>
withPOST
method and that will go to the route wherepostReset
is being fired, plus anemail
field that you already have. – Robo Robok