diff --git a/catchAdmin/login/Auth.php b/catchAdmin/login/Auth.php index 76293a7..9472f02 100644 --- a/catchAdmin/login/Auth.php +++ b/catchAdmin/login/Auth.php @@ -1,8 +1,8 @@ where('name', $params['name']) - // ->where('password', $params['password']) - ->first(); - - if (!password_verify($params('password'), $user->password)) { + $user = Users::where('username', $params['name'])->find(); + if (!password_verify($params['password'], $user->password)) { throw new LoginFailedException('登陆失败, 请检查用户名和密码'); } + if ($user->status == Users::DISABLE) { + throw new LoginFailedException('该用户已被禁用'); + } + + // 记录用户登录 + $user->last_login_ip = ip2long(request()->ip()); + $user->last_login_time = time(); + $user->save(); + Session::set($this->loginUser, $user); return true; diff --git a/catchAdmin/login/controller/Index.php b/catchAdmin/login/controller/Index.php index feb0217..e45d367 100644 --- a/catchAdmin/login/controller/Index.php +++ b/catchAdmin/login/controller/Index.php @@ -3,9 +3,10 @@ namespace catchAdmin\login\controller; use catchAdmin\login\Auth; use catchAdmin\login\request\LoginRequest; -use catcher\base\BaseController; +use catcher\base\CatchController; +use catcher\CatchResponse; -class Index extends BaseController +class Index extends CatchController { /** * 登录 @@ -25,11 +26,13 @@ class Index extends BaseController * @time 2019年11月28日 * @param LoginRequest $request * @return bool|string + * @throws \cather\exceptions\LoginFailedException * @throws \app\exceptions\LoginFailedException */ public function login(LoginRequest $request) { - (new Auth())->login($request->post()); + return (new Auth())->login($request->param()) ? + CatchResponse::success('', '登录成功') : CatchResponse::success('', '登录失败'); } /** diff --git a/catchAdmin/login/request/LoginRequest.php b/catchAdmin/login/request/LoginRequest.php index 04ba045..392d3c5 100644 --- a/catchAdmin/login/request/LoginRequest.php +++ b/catchAdmin/login/request/LoginRequest.php @@ -1,9 +1,9 @@ 'require|max:25', 'password|密码' => 'require', - 'captcha|验证码' => 'require|captcha' + // 'captcha|验证码' => 'require|captcha' ]; } diff --git a/catchAdmin/login/view/index.html b/catchAdmin/login/view/index.html index 26f9fc6..8e44f37 100644 --- a/catchAdmin/login/view/index.html +++ b/catchAdmin/login/view/index.html @@ -106,7 +106,13 @@ type: 'post', data: obj.field, success: function(response) { - layer.msg(response.msg) + layer.msg(response.msg, { + icon: 1, + time: 2000 //2秒关闭(如果不配置,默认是3秒) + }, function(){ + //do something + window.location.href = '/'; + }) } }); return false;