How to override default forgot password mechanism of Laravel 5.6?

邮差的信 提交于 2019-12-24 23:30:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!