diff --git a/src/plugin/admin/api/Middleware.php b/src/plugin/admin/api/Middleware.php index 02cc844..20d5540 100644 --- a/src/plugin/admin/api/Middleware.php +++ b/src/plugin/admin/api/Middleware.php @@ -1,13 +1,14 @@ expectsJson()) { $response = json(['code' => $code, 'msg' => $msg, 'type' => 'error']); } else { - $response = \response($msg, 401); + if ($code === 401) { + $response = response(<< + if (self !== top) { + parent.location.reload(); + } + +EOF + ); + } else { + $request->app = ''; + $request->plugin = 'admin'; + $response = view('common/error/403')->withStatus(403); + } } } else { $response = $request->method() == 'OPTIONS' ? response('') : $handler($request); @@ -38,4 +52,4 @@ class Middleware implements MiddlewareInterface return $response; } -} \ No newline at end of file +} diff --git a/src/plugin/admin/app/controller/InstallController.php b/src/plugin/admin/app/controller/InstallController.php index a6fcf8b..d62caa1 100644 --- a/src/plugin/admin/app/controller/InstallController.php +++ b/src/plugin/admin/app/controller/InstallController.php @@ -198,15 +198,17 @@ EOF; if ($password != $password_confirm) { return $this->json(1, '两次密码不一致'); } - if (Admin::first()) { - return $this->json(1, '后台已经安装完毕,无法通过此页面创建管理员'); - } if (!is_file($config_file = base_path() . '/plugin/admin/config/database.php')) { return $this->json(1, '请先完成第一步数据库配置'); } $config = include $config_file; $connection = $config['connections']['mysql']; $pdo = $this->getPdo($connection['host'], $connection['username'], $connection['password'], $connection['port'], $connection['database']); + + if ($pdo->query('select * from `wa_admins`')->fetchAll()) { + return $this->json(1, '后台已经安装完毕,无法通过此页面创建管理员'); + } + $smt = $pdo->prepare("insert into `wa_admins` (`username`, `password`, `nickname`, `created_at`, `updated_at`) values (:username, :password, :nickname, :created_at, :updated_at)"); $time = date('Y-m-d H:i:s'); $data = [ diff --git a/src/plugin/admin/app/controller/TableController.php b/src/plugin/admin/app/controller/TableController.php index 66ee09a..bed149b 100644 --- a/src/plugin/admin/app/controller/TableController.php +++ b/src/plugin/admin/app/controller/TableController.php @@ -103,6 +103,7 @@ class TableController extends Base $primary_key_count = 0; foreach ($columns as $index => $item) { + $columns[$index]['field'] = trim($item['field']); if (!$item['field']) { unset($columns[$index]); continue; @@ -207,6 +208,7 @@ class TableController extends Base $primary_key_count = $auto_increment_count = 0; foreach ($columns as $index => $item) { + $columns[$index]['field'] = trim($item['field']); if (!$item['field']) { unset($columns[$index]); continue; diff --git a/src/plugin/admin/app/functions.php b/src/plugin/admin/app/functions.php index 47b0879..1fed316 100644 --- a/src/plugin/admin/app/functions.php +++ b/src/plugin/admin/app/functions.php @@ -3,11 +3,9 @@ * Here is your custom functions. */ -use app\model\User; +use plugin\admin\app\model\User; use plugin\admin\app\model\Admin; use plugin\admin\app\model\AdminRole; -use plugin\admin\app\model\Role; -use plugin\admin\app\model\Rule; /** * 当前管理员id @@ -138,4 +136,4 @@ function refresh_user_session(bool $force = false) unset($user['password']); $user['session_last_update_time'] = $time_now; $session->set('user', $user); -} \ No newline at end of file +} diff --git a/src/plugin/admin/app/middleware/AccessControl.php b/src/plugin/admin/app/middleware/AccessControl.php index 38fa701..081d0ee 100644 --- a/src/plugin/admin/app/middleware/AccessControl.php +++ b/src/plugin/admin/app/middleware/AccessControl.php @@ -37,6 +37,7 @@ class AccessControl implements MiddlewareInterface EOF ); } else { + $request->app = ''; $request->plugin = 'admin'; $response = view('common/error/403')->withStatus(403); }