richardev
139
14
Laravel

Password reset not returning error messages on validation

Posted 1 week ago by richardev

After reseting password, user gets e-mail with password reset link & token. By opening this link user is presented with Password Reset form (view). Until this point all works great.. but whenever I pass wrong e-mail to trigger "email not valid" error warning, it gives me nothing.

reset form

Inspecting C:\Users\richa\Projects\globeguru\cms\vendor\laravel\framework\src\Illuminate\Foundation\Auth\ResetsPasswords.php I came across responsibe function on line 3:

public function reset(Request $request)
    {
        $request->validate($this->rules(), $this->validationErrorMessages());

        // Here we will attempt to reset the user's password. If it is successful we
        // will update the password on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.
        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        // If the password was successfully reset, we will redirect the user back to
        // the application's home authenticated view. If there is an error we can
        // redirect them back to where they came from with their error message.
        return $response == Password::PASSWORD_RESET
                    ? $this->sendResetResponse($request, $response)
                    : $this->sendResetFailedResponse($request, $response);
    }

This line:

 $request->validate($this->rules(), $this->validationErrorMessages());

Which brings me to this function:

protected function validationErrorMessages()
    {
        return [];
    }

My question is - how can I trigger the error message and return it via validationErrorMessages() function?

UPDATE

Here is the reset form HTML

@section('reset-form')
    <div class="alert-container" >
        @if (session('status'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <p><strong>Success!</strong></p>
                <p>{{ session('alert') }}</p>
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        @endif

        @error('email')
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <p><strong>Error!</strong></p>
            <p>{{ $message }}</p>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        @enderror

        @error('password')
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <p><strong>Error!</strong></p>
            <p>{{ $message }}</p>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        @enderror

        @error('password_confirmation')
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            <p><strong>Error!</strong></p>
            <p>{{ $message }}</p>
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        @enderror
    </div>

    <div class="gg-login-wrap">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ __('auth.reset_title') }}</h5>
                </div>
                <div class="modal-body">
                    <form class="gg-login" method="POST" action="{{ route('password.update') }}">
                        @csrf

                        <div class="form-group edit-input-wrap">
                            <input id="email" type="email" class="form-control edit-input @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
                            <label for="email">{{ __('auth.email') }}</label>

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                        <div class="form-group edit-input-wrap">
                            <input id="password" type="password" class="form-control edit-input @error('password') is-invalid @enderror" name="password" required autocomplete="current-password">
                            <label for="password">{{ __('auth.password') }}</label>

                            @error('password')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                        <div class="form-group edit-input-wrap">
                            <input id="password_confirmation" type="password" class="form-control" name="password_confirmation" required autocomplete="password_confirmation">
                            <label for="password_confirmation">{{ __('auth.password_repeat') }}</label>

                            @error('password_confirmation')
                            <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                        <input type="submit" class="btn btn-primary" value="{{ __('auth.reset') }}">
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.