2

I have this code:

$.ajax({
    url: "/password/email", 
    data: {
        _token: $(".modal-forgotpass-content input[name='_token']").val(),
        email: $(".modal-forgotpass-content input[name='email']").val()
    },
    type: "POST",
    success: function(data) {
        alert("Successful : link send");
    },
    error: function(e) {
        alert("Faild: link not send");
    }
});

Controller (this function comes with Laravel 5.4) :

public function sendResetLinkEmail(Request $request)
{
    $this->validate($request, ['email' => 'required|email']);

    // We will send the password reset link to this user. Once we have attempted
    // to send the link, we will examine the response then see the message we
    // need to show to the user. Finally, we'll send out a proper response.
    $response = $this->broker()->sendResetLink($request->only('email'));

    return $response == Password::RESET_LINK_SENT
        ? $this->sendResetLinkResponse($response)
        : $this->sendResetLinkFailedResponse($request, $response);
}

Routes :

Auth::routes();

This code works well, but it sends the password reset link to all emails even if the email does not exist in database (users table). I want the link to be sent only to the emails that already exist in the user table.

1 Answer 1

1

Instead of using validate like

$this->validate($request, ['email' => 'required|email']);

Validate it like below

$this->validate($request, ['email' => 'required|email|exists:users']);

This should validate if user email exists in database or not.

Sign up to request clarification or add additional context in comments.

2 Comments

@IlhamGuezzoula If your the email is not in the column called "id" you need exists:users,<emailColumn>
On my end it is showing message Method [getBroker] does not exist on [App\Http\Controllers\Auth\ForgotPasswordController]. exception BadMethodCallException

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.