问题
I wanted to login the user if his status field of users table was set to 1 otherwise not. So this problem was solved in this question which I had asked.
How to override default login mechanism of Laravel 5.6?
But now I am having another problem. When a user whose status is 0(not active) clicks the default forgot password link in login page and enters his email address and then clicks the reset link and fills the new password, he automatically gets logged in even though his status is 0(not active).
So how can I prevent the forgot password mechanism if user's status is 0 ?
回答1:
Go to ForgotPasswordController and paste it. the same mechanism exist here . therefor I am not explaining properly.
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
$userStatus=User::where('email','=',$request->email)->limit(1)->get();
if (isset($userStatus)) {
if ($userStatus[0]->role==0) {
return redirect()->back()->with(['massage'=>'Please activate account first']);
}
}
// 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);
}
来源:https://stackoverflow.com/questions/51076276/how-to-override-default-forgot-password-mechanism-of-laravel-5-6