Laravel 5.4 使用 AJAX 重置密码
Laravel 5.4 password reset using AJAX
我有这个代码:
$.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");
}
});
控制器(此功能自带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);
}
路线:
Auth::routes();
此代码运行良好,但它会将密码重置 link 发送到所有电子邮件,即使该电子邮件不存在于数据库中(用户 table)。我希望 link 仅发送到用户 table.
中已存在的电子邮件
而不是像
那样使用验证
$this->validate($request, ['email' => 'required|email']);
像下面这样验证它
$this->validate($request, ['email' => 'required|email|exists:users']);
这应该验证用户电子邮件是否存在于数据库中。
我有这个代码:
$.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");
}
});
控制器(此功能自带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);
}
路线:
Auth::routes();
此代码运行良好,但它会将密码重置 link 发送到所有电子邮件,即使该电子邮件不存在于数据库中(用户 table)。我希望 link 仅发送到用户 table.
中已存在的电子邮件而不是像
那样使用验证$this->validate($request, ['email' => 'required|email']);
像下面这样验证它
$this->validate($request, ['email' => 'required|email|exists:users']);
这应该验证用户电子邮件是否存在于数据库中。