Laravel覆盖身份验证验证

时间:2018-08-25 13:39:05

标签: php laravel-5.5

我试图通过检查用户是否确认了他/她的电子邮件地址来覆盖自定义的Laravel身份验证。同时,我想记录身份验证尝试。 我正在尝试使用在EventServiceProvider.php中注册的两个侦听器来实现后者。

'Illuminate\Auth\Events\Login' => [
    'App\Listeners\LogSuccessfulLogin',
],
'Illuminate\Auth\Events\Failed' => [
    'App\Listeners\LogFailedAuthenticationAttempt',
],

在app / Http / Controllers / Auth / LoginController.php中,我有以下内容。

/**
 * Validate the user login request.
 * Override vendor method.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return void
 */
protected function validateLogin(Request $request)
{
    $rules =  [
        'email' => [
            'required',
            'string',
            'exists:users,email,confirmed,1',
        ],
        'password' => [
            'required',
            'string',
        ],
    ];

    $messages = [
        'email.exists' => 'The combination of email address and password is unknown or the email address has not yet been validated.',
    ];

    $validator = Validator::make($request->all(), $rules, $messages);

    // $this->validate($request, $rules, $messages);

    if ($validator->fails()) {
        return redirect('nl')
                    ->withErrors($validator)
                    ->withInput();
    }
}

问题在于,通过这种方式似乎可以忽略检查用户是否确认了电子邮件地址。并且使用auth:middleware。现在更改此:

//$validator = Validator::make($request->all(), $rules, $messages);

$this->validate($request, $rules, $messages);

现在将检查地址是否已确认,但是永远不会调用Failed事件。如何实现调用事件和自定义规则的功能?

0 个答案:

没有答案