From 109cb7279a49f6e5c998f0d0f36eb061d00268c6 Mon Sep 17 00:00:00 2001 From: wuyanwen Date: Thu, 12 Dec 2019 18:52:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catchAdmin/login/controller/Index.php | 19 +++++++++++++--- catchAdmin/login/request/LoginRequest.php | 2 +- catchAdmin/login/route.php | 9 +++++--- catchAdmin/login/view/index.html | 27 ++++++++++++++--------- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/catchAdmin/login/controller/Index.php b/catchAdmin/login/controller/Index.php index e45d367..ed339f9 100644 --- a/catchAdmin/login/controller/Index.php +++ b/catchAdmin/login/controller/Index.php @@ -1,10 +1,11 @@ login($request->param()) ? + return Auth::login($request->param()) ? CatchResponse::success('', '登录成功') : CatchResponse::success('', '登录失败'); } @@ -43,10 +44,22 @@ class Index extends CatchController */ public function logout(): bool { - if ((new Auth())->logout()) { + if (Auth::logout()) { return redirect(url('login')); } return false; } + + /** + * + * @time 2019年12月12日 + * @param Captcha $captcha + * @param null $config + * @return \think\Response + */ + public function captcha(Captcha $captcha, $config = null): \think\Response + { + return $captcha->create($config); + } } \ No newline at end of file diff --git a/catchAdmin/login/request/LoginRequest.php b/catchAdmin/login/request/LoginRequest.php index 392d3c5..a8b709d 100644 --- a/catchAdmin/login/request/LoginRequest.php +++ b/catchAdmin/login/request/LoginRequest.php @@ -9,7 +9,7 @@ class LoginRequest extends CatchRequest { // TODO: Implement rules() method. return [ - 'name|用户名' => 'require|max:25', + 'email|用户名' => 'email', 'password|密码' => 'require', // 'captcha|验证码' => 'require|captcha' ]; diff --git a/catchAdmin/login/route.php b/catchAdmin/login/route.php index 669d695..10665ea 100644 --- a/catchAdmin/login/route.php +++ b/catchAdmin/login/route.php @@ -1,8 +1,11 @@ get('login', '\catchAdmin\login\controller\Index/index'); +$router->get('login', '\catchAdmin\login\controller\Index@index'); # 登入 -$router->post('login', '\catchAdmin\login\controller\Index/login'); +$router->post('login', '\catchAdmin\login\controller\Index@login'); # 登出 -$router->post('logout', '\catchAdmin\login\controller\Index/logout'); +$router->post('logout', '\catchAdmin\login\controller\Index@logout'); +# 验证码 +$router->get('catch/captcha/[:config]','\catchAdmin\login\controller\Index@captcha'); + diff --git a/catchAdmin/login/view/index.html b/catchAdmin/login/view/index.html index 8e44f37..4307043 100644 --- a/catchAdmin/login/view/index.html +++ b/catchAdmin/login/view/index.html @@ -38,8 +38,8 @@
- +
@@ -58,7 +58,7 @@ autocomplete="off" lay-verType="tips" lay-verify="required" required/>
- captcha + captcha
@@ -106,13 +106,20 @@ type: 'post', data: obj.field, success: function(response) { - layer.msg(response.msg, { - icon: 1, - time: 2000 //2秒关闭(如果不配置,默认是3秒) - }, function(){ - //do something - window.location.href = '/'; - }) + if (response.code === 10000) { + layer.msg(response.msg, { + icon: 1, + time: 2000 //2秒关闭(如果不配置,默认是3秒) + }, function () { + //do something + window.location.href = '/'; + }) + } else { + layer.msg(response.msg, { + icon: 2, + time: 2000 //2秒关闭(如果不配置,默认是3秒) + }) + } } }); return false;