Parcourir la source

6-8验证码校验

Home il y a 5 ans
Parent
commit
530c2b2416
3 fichiers modifiés avec 21 ajouts et 4 suppressions
  1. 17 0
      app/admin/controller/Login.php
  2. 1 1
      app/middleware.php
  3. 3 3
      public/static/admin/js/login.js

+ 17 - 0
app/admin/controller/Login.php

@@ -21,6 +21,23 @@ class Login extends BaseController
 
     public function check()
     {
+        if (!$this->request->isPost()) {
+            return show(config('status.error'), '请求方式错误');
+        }
+
+        // 参数校验 1、原生方式  2、TP6 验证机制
+        $username = $this->request->param('username', '', 'trim');
+        $password = $this->request->param('password', '', 'trim');
+        $captcha = $this->request->param('captcha', '', 'trim');
+        if (empty($username) || empty($password) || empty($captcha)) {
+            return show(config('status.error'), '参数不能为空');
+        }
+        // 验证码校验
+        if (!captcha_check($captcha)) {
+            // 验证码校验失败
+            return show(config('status.error'), '验证码不正确');
+        }
+
         return show(config('status.success'), '登陆成功');
     }
 }

+ 1 - 1
app/middleware.php

@@ -6,5 +6,5 @@ return [
     // 多语言加载
     // \think\middleware\LoadLangPack::class,
     // Session初始化
-    // \think\middleware\SessionInit::class
+    \think\middleware\SessionInit::class
 ];

+ 3 - 3
public/static/admin/js/login.js

@@ -39,9 +39,9 @@ layui.use(['form'], function () {
         $.ajax({
             url,
             data,
-            type:"POST",
-            success(res){
-                if(res.status == 1){
+            type: "POST",
+            success(res) {
+                if (res.status == 1) {
                     layer.msg('登录成功', function () {
                         window.location = '/admin/index/index.html';
                     });