0
votes

I'm having some issues with password reset process in Laravel 5.1

Step to produce:

  1. Forget password page (Enter password and a reset link will be sent as email)
  2. 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?

1
I'm not sure what you are expecting. E-mail here is not supposed to be passed. old() is only to retrieve previously typed value after redirection when using withInput().Robo Robok
reset post request goes to Auth\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-passwordsHADI
I mean yes - it goes to postReset, but only when you type it on your own. old() has nothing to do with that. You just need a <form> with POST method and that will go to the route where postReset is being fired, plus an email field that you already have.Robo Robok
I am actually working on a existing work and fixing a bug. The password form actually does have the email field in hidden. So user can't input email. As it was hidden I thought email field might be automatically populated. But after dig in, it seems email field need to fill up along with new password and repeat password. I will update that email field to normal instead of hidden so that user can fill up.HADI
Also explanation about old is correct also there is an additional feature is when we will use illuminate HTML package and pass object to form old function get automated populated. No matter you typed it or not.HADI

1 Answers

0
votes

Just add the following code in Model User.php

 /**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token.'/'.$this->email));
}