2
votes

I recently upgraded my laravel 5.6 project to laravel 5.7, I am experiencing an issue right after I upraded to laravel 5.7. when I enter a registered email, password reset email is sent successfully and the correponding session status message is displayed in the page but when I enter a non registered email the $errors->first('email') displays passwords.user instead if displaying We can't find a user with that e-mail address. (laravel predefined error message).

How do I solve this problem???

auth/passwords/email.blade.php:

<form action="{{ route('password.email') }}" class="forgot_Form text-center" method="POST" id="forgot_password">
            @csrf
            <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                <input type="email" class="form-control email" name="email" id="email" placeholder="Email" value="{{ old('email') }}">
                @if ($errors->has('email'))
                    <span class="label label-danger">
                        <strong>{{ $errors->first('email') }}</strong>
                    </span>
                @endif
            </div>
            <button type="submit" class="btn submit-btn">
                Send Password Reset Link
            </button>
        </form>

ForgotPasswordController.php:

class ForgotPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset emails and
    | includes a trait which assists in sending these notifications from
    | your application to your users. Feel free to explore this trait.
    |
    */

    use SendsPasswordResetEmails;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }
}

Result:

enter image description here

I am using laravel built-in authentication

3

3 Answers

3
votes

For some reason Laravel have changed the password reset validation errors to make use of localization and translations.

To solve your issue:

  1. Create a file named passwords.php within resources/lang/en directory.
  2. Within this file you can return an array of any key that comes after the passwords. in the validation message.

For example:

return [
    'user' => 'We can't find a user with that e-mail address.'
];
0
votes

Try overwriting the validation method provided by the trait SendsPasswordResetEmails:

In ForgotPasswordController, add this method:

use Illuminate\Http\Request;

...

protected function validateEmail(Request $request)
{
    $this->validate($request, 
        [
            'email' => 'required|email'
        ],[
            'email.email' => '<Your custom email error message>',
            'email.required' => '<Your custom email error message>'
        ]);
}
0
votes

In login controller put the following code :

 public function verifyUser($token)
    {
        $verifyUser = VerifyUser::where('token', $token)->first();
        if(isset($verifyUser) ){

            if(!$user->verified) {
                $verifyUser->verified = 1;
                $verifyUser->save();

                $status = "Your e-mail is verified. You can now login.";
            }else{
                $status = "Your e-mail is already verified. You can now login.";
            }
        }else{
            return redirect('/login')->with('warning', "Sorry your email cannot be identified.");
        }

        return redirect('/login')->with('status', $status);
    }