ソースを参照

6-9后台用户登录校验

Home 5 年 前
コミット
013610dc89
3 ファイル変更58 行追加0 行削除
  1. 16 0
      app/admin/controller/Login.php
  2. 37 0
      app/common/model/mysql/AdminUser.php
  3. 5 0
      config/status.php

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

@@ -9,6 +9,7 @@
 namespace app\admin\controller;
 
 use app\BaseController;
+use app\common\model\mysql\AdminUser;
 use think\facade\View;
 
 
@@ -19,6 +20,11 @@ class Login extends BaseController
         return View::fetch();
     }
 
+    public function md5()
+    {
+        echo md5('admin_singwa_abc');
+    }
+
     public function check()
     {
         if (!$this->request->isPost()) {
@@ -38,6 +44,16 @@ class Login extends BaseController
             return show(config('status.error'), '验证码不正确');
         }
 
+        $adminUserObj = new AdminUser();
+        $adminUser = $adminUserObj->getAdminUserByUsername($username);
+        if (empty($adminUser) || $adminUser->status != config('status.mysql.table_normal')) {
+            return show(config('status.error'), '不存在该用户');
+        }
+        $adminUser = $adminUser->toArray();
+        if ($adminUser['password'] !== md5($password . '_singwa_abc')) {
+            return show(config('status.error'), '密码错误');
+        }
+
         return show(config('status.success'), '登陆成功');
     }
 }

+ 37 - 0
app/common/model/mysql/AdminUser.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * Created by PhpStorm
+ * User:林志杰
+ * Email:[email protected]
+ * Motto:纵有疾风起,人生不言弃!
+ * Time:2020/1/3 0:29
+ */
+
+namespace app\common\model\mysql;
+
+
+use think\Model;
+
+class AdminUser extends Model
+{
+    /**
+     * 根据用户名获取后端用户表的数据
+     * @param $username
+     * @return array|bool|Model|null
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getAdminUserByUsername($username)
+    {
+        if (empty($username)) {
+            return false;
+        }
+
+        $where = [
+            'username' => trim($username),
+        ];
+        $result = $this->where($where)->find();
+        return $result;
+    }
+}

+ 5 - 0
config/status.php

@@ -14,4 +14,9 @@ return [
     "user_is_register" => -2,
     "action_not_fund" => -3,
     "controller_not_fund" => -4,
+    "mysql" => [
+        "table_normal" => 1, // 正常
+        "table_pedding" => 0, // 待审核
+        "table_delete" => 99, // 删除
+    ]
 ];