在laravel中的我的登录控制器中添加ToomAnyAttentits

在laravel中的我的登录控制器中添加ToomAnyAttentits,laravel,lockout,Laravel,Lockout,我需要添加ToomanyLogin在登录时尝试的功能。现在它不起作用了。Iam使用Laravel Framework 5.1.45(LTS)。 下面提到了我使用的代码。 我的控制器功能是 <?php use App\Libraries\SessionHelper; use App\Libraries\ConfigUtils; use App\Libraries\GeneralLib; use App\Models\OrgSettings; u

我需要添加ToomanyLogin在登录时尝试的功能。现在它不起作用了。Iam使用Laravel Framework 5.1.45(LTS)。 下面提到了我使用的代码。 我的控制器功能是

    <?php
    use App\Libraries\SessionHelper;
    use App\Libraries\ConfigUtils;
    use App\Libraries\GeneralLib;
    use App\Models\OrgSettings;
    use App\Http\Controllers\Controller;
    use Illuminate\Foundation\Auth\ThrottlesLogins;
    use Illuminate\Foundation\Auth\AuthenticatesUsers;
    use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

    class LoginController extends Controller {
     use AuthenticatesAndRegistersUsers, ThrottlesLogins;

      public function doLogin() {
        $email = Input::get('email');
        $pass = Input::get('password');
        $candidate_login_user = User::getUserByEmail($email);
        $data = User::authenticate($email, $pass);
        if (empty($data)) {
          User::logFailedAuthentication($email, $candidate_login_user->organization);
          Session::flash('error', "Incorrect email or password.");
          return Redirect::to('/login');
        }

    }

由于您正在实现自己的登录操作,因此仅向
登录控制器添加特征来实现限制是不够的

您需要从
doLogin
操作中检查
hastoomanylogintruments
方法,并在必要时自行触发锁定事件

公共函数doLogin(\illumb\Http\Request$Request){
如果($this->hastoomanyLogin尝试($request)){
$this->fireLockoutEvent($request);
返回$this->sendLockoutResponse($request);
}
$email=Input::get('email');
$pass=Input::get('password');
$candidate\u login\u user=user::getUserByEmail($email);
$data=User::authenticate($email,$pass);
if(空($数据)){
用户::logFailedAuthentication($email、$candidate\u login\u User->organization);
会话::flash('错误',“不正确的电子邮件或密码”);
$this->incrementLoginAttents($request);
返回Redirect::to('/login');
}
}

总之,我认为您最好只使用内置的Auth控制器来处理您的登录(或者至少使用它们作为起点),而不是重新实现您自己的登录。

因为您要实现自己的登录操作,所以仅将特性添加到
LoginController
来实现限制是不够的

您需要从
doLogin
操作中检查
hastoomanylogintruments
方法,并在必要时自行触发锁定事件

公共函数doLogin(\illumb\Http\Request$Request){
如果($this->hastoomanyLogin尝试($request)){
$this->fireLockoutEvent($request);
返回$this->sendLockoutResponse($request);
}
$email=Input::get('email');
$pass=Input::get('password');
$candidate\u login\u user=user::getUserByEmail($email);
$data=User::authenticate($email,$pass);
if(空($数据)){
用户::logFailedAuthentication($email、$candidate\u login\u User->organization);
会话::flash('错误',“不正确的电子邮件或密码”);
$this->incrementLoginAttents($request);
返回Redirect::to('/login');
}
}

总之,我认为您最好使用内置的Auth控制器来处理您的登录(或者至少使用它们作为起点),而不是重新实现您自己的登录。

“现在它不工作了”-以什么方式?没有验证,或者没有限制尝试,或者你得到了500个错误,或者空白页?控制器类底部的随机
=
符号是什么?即使多次登录失败,也不会显示太多登录尝试。如何实现这一点?我添加了use-illumb\Foundation\Auth\ThrottlesLogins;使用Illumb\Foundation\Auth\AuthenticatesUsers;在控制器和我的类内部,LoginController扩展控制器{使用AuthenticatesAndRegistersUsers,ThrottlesLogins;但在我上面提到的代码中不工作的是
doLogin
your own code?这就是用户提交表单时您要路由到的操作?“现在不工作了”-以何种方式?未验证或不限制尝试,或您收到500个错误或空白页?控制器类底部的随机符号是什么?即使在多次登录失败后,也不会显示太多登录尝试。如何实现这一点?我添加了use Illumb\Foundation\Auth\ThrottlesLogins;use illluminate\Foundation\Auth\authenticateUsers;在控制器中和我的类中LoginController扩展控制器{使用AuthenticatesAndRegistersUsers,ThrottlesLogins;但在我上面提到的代码中不起作用的是
doLogin
您自己的代码?这就是您在用户提交表单时路由到的操作?我添加了此代码。但是前端登录中没有显示错误消息。我添加了此代码。但是错误消息前端登录中未显示年龄。
    <form action="login" method="post">
                    <div class="body bg-gray">
                       <div class="alert alert-danger">
        <strong >Whoops!</strong> There were some problems with your input.<br><br>
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

                        <?php
                            Session::forget('error');
                            Session::forget('success');
                        ?>
                        <div class="form-group">
                            <input type="email" name="email" class="form-control"
                                placeholder="email"/>
                        </div>
                        <div class="form-group">
                            <input type="password" name="password"
                                class="form-control" placeholder="password"/>
                        </div>