dcatadmin通过用户表的status字段限制用户登录.
通过用户表status字段的值限制用户登录.
AuthController 继承自 BaseAuthController
重写AuthController 类的 postLogin 方法 (从父类BaseAuthController复制一份postLogin的方法)
if ($this->guard()->attempt($credentials, $remember)) {
return $this->sendLoginResponse($request);
}
改造以上代码段
//$credentials['mark'] = 1;//查询条件增加mark=1的用户
if ($this->guard()->attempt($credentials, $remember)) {
//判断用户数据 status字段的值是否为禁用状态
if($this->guard()->user()->status == User::STATUS_LOCK){
return $this->validationErrorsResponse([$this->username() => '账号未启用,请联系管理员']);
}
return $this->sendLoginResponse($request);
}
这样就能通过用户表的status字段,判断用户是否允许登录
本作品采用《CC 协议》,转载必须注明作者和本文链接
为什么不在登录前就验证完这些数据呢?直接
auth()->guard($guard_name)->login($user);