Merge branch 'main' of github.com:webman-php/admin into main
This commit is contained in:
commit
0d94b22820
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
namespace plugin\admin\api;
|
||||
|
||||
use ReflectionException;
|
||||
use Webman\Http\Request;
|
||||
use Webman\Http\Response;
|
||||
use Webman\MiddlewareInterface;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
/**
|
||||
* 对外提供的webman-admin鉴权中间件
|
||||
* 对外提供的鉴权中间件
|
||||
*/
|
||||
class Middleware implements MiddlewareInterface
|
||||
{
|
||||
@ -16,7 +17,7 @@ class Middleware implements MiddlewareInterface
|
||||
* @param Request $request
|
||||
* @param callable $handler
|
||||
* @return Response
|
||||
* @throws \ReflectionException
|
||||
* @throws ReflectionException
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function process(Request $request, callable $handler): Response
|
||||
@ -30,7 +31,20 @@ class Middleware implements MiddlewareInterface
|
||||
if ($request->expectsJson()) {
|
||||
$response = json(['code' => $code, 'msg' => $msg, 'type' => 'error']);
|
||||
} else {
|
||||
$response = \response($msg, 401);
|
||||
if ($code === 401) {
|
||||
$response = response(<<<EOF
|
||||
<script>
|
||||
if (self !== top) {
|
||||
parent.location.reload();
|
||||
}
|
||||
</script>
|
||||
EOF
|
||||
);
|
||||
} else {
|
||||
$request->app = '';
|
||||
$request->plugin = 'admin';
|
||||
$response = view('common/error/403')->withStatus(403);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
|
||||
|
@ -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 = [
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -37,6 +37,7 @@ class AccessControl implements MiddlewareInterface
|
||||
EOF
|
||||
);
|
||||
} else {
|
||||
$request->app = '';
|
||||
$request->plugin = 'admin';
|
||||
$response = view('common/error/403')->withStatus(403);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user