宽屏模式

laravel 5.5 禁用账户权限限制;

Laraval自带的用户认证系统Auth非常强大易用, 若想在用户登录时对禁用的用户进行登录时的限制, 那么就需要重写项目目录下\app\Http\Controllers\Auth\LoginController.phplogin方法;
你可以在LoginController中看到该类中的一行 use AuthenticatesUsers;
login方法就定义在AuthenticatesUsers这个trait里面.你可以在这个trait中看到:

/**
     * Handle a login request to the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
     */
    public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if ($this->attemptLogin($request)) {
            return $this->sendLoginResponse($request);
        }

在登录时, 系统先通过validateLogin方法判断传输过来的账号密码是否符合预设的规则;
在通过hasTooManyLoginAttempts方法判断输入密码错误次数是否达到上限, 账号是否被冻结等
最后再通过attemptLogin方法去验证账号密码的正确性, 进行登录;

所以, 当我们需要增加用户登录的验证时, 只需要在第三步中加入 需要验证的内容即可;

  if ($this->attemptLogin($request)) {
            if(Auth::user()->state==2){
                die('您的账户已被禁止,请联系管理员');
            };
            return $this->sendLoginResponse($request);
        }

  • 上一篇: 没有了
  • 下一篇: git回退
Larwas
请先登录后发表评论
  • latest comments
  • 总共0条评论