【问题标题】:How to override default forgot password mechanism of Laravel 5.6?如何覆盖 Laravel 5.6 的默认忘记密码机制?
【发布时间】:2018-12-07 03:30:15
【问题描述】:

如果用户表的状态字段设置为 1,我想登录用户,否则不登录。所以这个问题在我问的这个问题中得到了解决。

How to override default login mechanism of Laravel 5.6?

但现在我遇到了另一个问题。当状态为0(未激活)的用户点击登录页面中的默认忘记密码链接并输入他的电子邮件地址,然后点击重置链接并填写新密码,即使他的状态为 0(未激活),他也会自动登录。

如果用户状态为0,如何防止忘记密码机制?

【问题讨论】:

  • 跟踪路由并找到忘记密码函数被调用的位置,并从那里查找将状态更改为 0 的查询。
  • 从最后一个答案中,如果您删除 'status'=>1 那么它将按您的意愿工作

标签: php laravel-5.6 forgot-password


【解决方案1】:

转到 ForgotPasswordController 并粘贴它。存在相同的机制 here 。因此我没有正确解释。

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);
    }

【讨论】:

  • 我认为有必要在 if($userStatus[0]->role==0) 之前包含 if(isset($userStatus)) 因为如果没有这样的用户可能会抛出错误电子邮件存在
  • 什么都不需要
  • 你可以改变角色的状态或任何你想要的
  • 尝试获取非对象错误的属性“状态”正在生成,因为如果提供了一些随机电子邮件,$userStatus 可以为空,因此只需包含 isset($userStatus) 以便我可以接受您的回答跨度>
  • 你是对的实际上我没有测试它。现在我用 isset() 更新了答案
猜你喜欢
  • 2018-12-07
  • 2013-04-12
  • 1970-01-01
  • 2014-02-12
  • 2018-10-20
  • 2018-06-18
  • 2018-03-27
  • 2017-01-22
  • 2021-02-18
相关资源
最近更新 更多