12 Commits

Author SHA1 Message Date
wolfcode
d99e168583 Update Install.php 2025-01-15 09:54:11 +08:00
wolfcode
d6bb1456fa build(dependencies): update composer dependencies and adjust view rendering
- Update topthink/think-view dependency to version ^2.0
- Modify view rendering in Install controller to use empty template path
2025-01-15 09:45:07 +08:00
wolfcode
91eac36371 refactor(view): remove redundant template path generation
- Remove unnecessary code that generates a template path based on the request pathinfo
- Simplify the render function by removing the conditional block that sets the template path
2025-01-15 09:28:15 +08:00
wolfcode
1e4486989a refactor(admin): improve login check middleware
- Rename $ignoreAuth to $ignoreLogin for better clarity
- Update comments for better code readability
- Modify Login controller to use $ignoreLogin instead of $ignoreAuth
2025-01-14 10:09:58 +08:00
wolfcode
f9f25b76dd Merge branch 'main' of https://github.com/easyadmin8/EasyAdmin8 2025-01-12 18:13:17 +08:00
wolfcode
7603cdfa7e feat(admin): add middleware annotation for login exemption
- Add MiddlewareAnnotation to CheckLogin middleware for login exemption
- Implement IGNORE_LOGIN constant in MiddlewareAnnotation
- Use MiddlewareAnnotation in Goods controller for login exemption

Signed-off-by: wolfcode <37436228+wolf-leo@users.noreply.github.com>
2025-01-12 18:12:28 +08:00
wolfcode
2e0cc85966 build(deps): update topthink/think-view to 2.0.0
- Change topthink/think-view dependency from ^2.0 to 2.0.0
- This update specifies an exact version to ensure compatibility and stability
2025-01-09 11:48:38 +08:00
wolfcode
5814fed0da Update Install.php 2025-01-09 11:32:25 +08:00
wolfcode
40f7ee82cd refactor(install): update view path delimiter
- Change the view path delimiter from '/' to '@' for the installation view
- This modification ensures consistency with the naming convention used in other parts of the application
2025-01-09 11:21:02 +08:00
wolfcode
936cb56c7f Update public.css 2025-01-08 21:38:48 +08:00
wolfcode
2d1940522c fix(View): automatically determine the template path if it is empty
- Add logic to automatically set the template path based on the controller and action if not explicitly defined
- Improve consistency in the 'iframeOpenTop' configuration by adding missing commas
2025-01-08 14:35:54 +08:00
wolfcode
264cf56ae4 fix(View): automatically determine the template path if it is empty
- Add logic to automatically set the template path based on the controller and action if not explicitly defined
- Improve consistency in the 'iframeOpenTop' configuration by adding missing commas
2025-01-08 14:25:54 +08:00
7 changed files with 26 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ use think\Response;
class Login extends AdminController class Login extends AdminController
{ {
protected bool $ignoreAuth = true; protected bool $ignoreLogin = true;
public function initialize(): void public function initialize(): void
{ {

View File

@@ -4,6 +4,7 @@ namespace app\admin\controller\mall;
use app\admin\model\MallCate; use app\admin\model\MallCate;
use app\admin\model\MallGoods; use app\admin\model\MallGoods;
use app\admin\service\annotation\MiddlewareAnnotation;
use app\common\controller\AdminController; use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation; use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation; use app\admin\service\annotation\NodeAnnotation;
@@ -66,4 +67,9 @@ class Goods extends AdminController
return $this->fetch(); return $this->fetch();
} }
#[MiddlewareAnnotation(ignore: MiddlewareAnnotation::IGNORE_LOGIN)]
public function no_check_login(Request $request): string
{
return '这里演示方法不需要经过登录验证';
}
} }

View File

@@ -7,6 +7,7 @@ use app\Request;
use Closure; use Closure;
use ReflectionClass; use ReflectionClass;
use ReflectionException; use ReflectionException;
use app\admin\service\annotation\MiddlewareAnnotation;
class CheckLogin class CheckLogin
{ {
@@ -24,13 +25,22 @@ class CheckLogin
$controllerClass = 'app\\admin\\controller\\' . $controller; $controllerClass = 'app\\admin\\controller\\' . $controller;
$classObj = new ReflectionClass($controllerClass); $classObj = new ReflectionClass($controllerClass);
$properties = $classObj->getDefaultProperties(); $properties = $classObj->getDefaultProperties();
$ignoreAuth = $properties['ignoreAuth'] ?? false; // 整个控制器是否忽略登录
$adminUserInfo = session('admin'); $ignoreLogin = $properties['ignoreLogin'] ?? false;
if (!$ignoreAuth) { $adminUserInfo = session('admin');
if (!$ignoreLogin) {
$noNeedCheck = $properties['noNeedCheck'] ?? []; $noNeedCheck = $properties['noNeedCheck'] ?? [];
if (in_array($action, $noNeedCheck)) { if (in_array($action, $noNeedCheck)) {
return $next($request); return $next($request);
} }
$reflectionMethod = new \ReflectionMethod($controllerClass, $action);
$attributes = $reflectionMethod->getAttributes(MiddlewareAnnotation::class);
foreach ($attributes as $attribute) {
$annotation = $attribute->newInstance();
$_ignore = (array)$annotation->ignore;
// 控制器中的某个方法忽略登录
if (in_array('LOGIN', $_ignore)) return $next($request);
}
if (empty($adminUserInfo)) { if (empty($adminUserInfo)) {
return redirect(__url('login/index')); return redirect(__url('login/index'));
} }

View File

@@ -10,6 +10,9 @@ final class MiddlewareAnnotation
/** 过滤日志 */ /** 过滤日志 */
const IGNORE_LOG = 'LOG'; const IGNORE_LOG = 'LOG';
/** 免登录 */
const IGNORE_LOGIN = 'LOGIN';
public function __construct(public string $type = '', public string|array $ignore = '') public function __construct(public string $type = '', public string|array $ignore = '')
{ {
} }

View File

@@ -249,7 +249,7 @@ class AdminController extends BaseController
'version' => env('APP_DEBUG') ? time() : ConfigService::getVersion(), 'version' => env('APP_DEBUG') ? time() : ConfigService::getVersion(),
'adminUploadUrl' => url('ajax/upload', [], false), 'adminUploadUrl' => url('ajax/upload', [], false),
'adminEditor' => sysConfig('site', 'editor_type') ?: 'wangEditor', 'adminEditor' => sysConfig('site', 'editor_type') ?: 'wangEditor',
'iframeOpenTop' => sysConfig('site', 'iframe_open_top') ?: 0, 'iframeOpenTop' => sysConfig('site', 'iframe_open_top') ?: 0,
]; ];
View::assign($data); View::assign($data);
} }

View File

@@ -41,7 +41,7 @@ class Install extends BaseController
]; ];
$currentHost = '://'; $currentHost = '://';
$result = compact('errorInfo', 'currentHost', 'isInstall', 'envInfo'); $result = compact('errorInfo', 'currentHost', 'isInstall', 'envInfo');
return view('index/install/index', $result); return view('index@install/index', $result);
} }
if ($errorInfo) $this->error($errorInfo); if ($errorInfo) $this->error($errorInfo);
$charset = 'utf8mb4'; $charset = 'utf8mb4';

View File

@@ -516,4 +516,5 @@ table样式
.wangEditor_div { .wangEditor_div {
z-index: 99999; z-index: 99999;
border: 1px solid var(--w-e-textarea-slight-border-color);
} }