Laravel 密码重置错误信息
Laravel passwordreset error message
我希望被阻止的用户无法执行密码重置 link,收到一条错误消息并被转发到一个页面。如果用户被阻止,则 2 将存储在 table 用户中,处于活动状态。我该怎么做?
我从 laravel 中找到了代码:
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// 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);
}
不需要覆盖sendResetLinkEmail
函数,你可以像这样覆盖validateEmail
protected function validateEmail(Request $request)
{
$this->validate($request,
['email' => ['required','email',
Rule::exists('users')->where(function ($query) {
$query->where('active', 1);
})
]
]
);
}
或
如果你想重定向到自定义 url 然后用这样的手动验证覆盖 sendResetLinkEmail
函数
public function sendResetLinkEmail(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => ['required', 'email',
Rule::exists('users')->where(function ($query) {
$query->where('active', 1);
})
]
]);
if ($validator->fails()) {
return redirect('some_other_url')
->with('fail', 'You can not request reset password, account is block');
}
// 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);
}
我希望被阻止的用户无法执行密码重置 link,收到一条错误消息并被转发到一个页面。如果用户被阻止,则 2 将存储在 table 用户中,处于活动状态。我该怎么做?
我从 laravel 中找到了代码:
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// 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);
}
不需要覆盖sendResetLinkEmail
函数,你可以像这样覆盖validateEmail
protected function validateEmail(Request $request)
{
$this->validate($request,
['email' => ['required','email',
Rule::exists('users')->where(function ($query) {
$query->where('active', 1);
})
]
]
);
}
或
如果你想重定向到自定义 url 然后用这样的手动验证覆盖 sendResetLinkEmail
函数
public function sendResetLinkEmail(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => ['required', 'email',
Rule::exists('users')->where(function ($query) {
$query->where('active', 1);
})
]
]);
if ($validator->fails()) {
return redirect('some_other_url')
->with('fail', 'You can not request reset password, account is block');
}
// 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);
}