Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel密码重置错误消息_Laravel_Blocked_Error Messaging - Fatal编程技术网

Laravel密码重置错误消息

Laravel密码重置错误消息,laravel,blocked,error-messaging,Laravel,Blocked,Error Messaging,我希望被阻止的用户不能执行密码重置链接,收到错误消息并被转发到页面。如果用户被阻止,则2存储在用户表中,处于活动状态。我该怎么做 我从laravel那里找到了代码: /** * Send a reset link to the given user. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\H

我希望被阻止的用户不能执行密码重置链接,收到错误消息并被转发到页面。如果用户被阻止,则2存储在用户表中,处于活动状态。我该怎么做

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

从密码重置令牌获取用户并检查
if($user->active==2)重定向('some_view_page')->带有('fail','Sorry,您的帐户被阻止')我必须停止发送电子邮件并转发错误消息。控制器ForgotPasswordController是否正确?我是在做验证吗?还是怎样我更新了我的问题是,在此函数中通过电子邮件获取用户,并检查
$user->active==2
,然后使用消息重定向。我可以在此函数中直接重定向用户吗?否,如果要重定向到其他url,则需要覆盖
sendResetLinkEmail
,并使用makeYes创建手动验证,我想转发用户并发出错误消息