2
votes

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

1 Answers

1
votes

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.