Laravel:在自定义登录控制器中使用节流阀 [英] Laravel: using throttle in a custom Login controller

查看:193
本文介绍了Laravel:在自定义登录控制器中使用节流阀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的登录控制器功能

This is my login controller function

   use ThrottlesLogins;
   protected $maxLoginAttempts = 3;
   protected $lockoutTime = 300;

 public function login(Request $request)
    {       

        if ($this->hasTooManyLoginAttempts($request))
        {
        $this->fireLockoutEvent($request);
        return $this->sendLockoutResponse($request);
        }

        $validator = Validator::make(Input::all() , ['credential' => 'required|min:2|max:255', 'password' => 'required|string|min:8', ]);
        $cred = $request->credential;
        $pw = $request->password;
        $remember = (Input::has('remember')) ? true : false;

        if (filter_var($cred, FILTER_VALIDATE_EMAIL))
          {
          if (Auth::guard('customers')->attempt(['email' => $cred, 'password' => $pw, 'verified' => 1], $remember))
            {
            return redirect()->route('front');
            }
            else
            {
            return redirect()->route('customer-login-page')->with('error', 'Your credentials do not match');
            }
          }
          else
          {
            if (Auth::guard('customers')->attempt(['contact' => $cred, 'password' => $pw], $remember))
             {
              return redirect()->intended(route('front'));
             }
            else
            {
            return redirect()->route('customer-login-page')->with('error', 'Your credentials do not match');
            }
          }

    }



  protected function hasTooManyLoginAttempts(Request $request)
    {
       return $this->limiter()->tooManyAttempts(
           $this->throttleKey($request), $this->maxLoginAttempts, $this->lockoutTime
       );
    }

它不起作用.我已经尝试了3次以上的失败登录尝试,但仍然没有受到限制.和 即使我发布了正确的凭据,登录和重定向仍然有效,但是当我检查请求时,我得到了

It's not working. I've tried failed login attempts more that 3 times and still not getting throttled. AND Even when I post the correct credentials, the login and redirect works but when I check the request I get a

302 FOUND错误

302 FOUND error

在网络"标签中

推荐答案

尝试

use Illuminate\Foundation\Auth\ThrottlesLogins;

已恢复

use ThrottlesLogins;

这篇关于Laravel:在自定义登录控制器中使用节流阀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆