fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -24,14 +24,15 @@ use Webman\Http\Request;
*/
class StaticFile implements MiddlewareInterface
{
public function process(Request $request, callable $next): Response
public function process(Request $request, callable $handler): Response
{
// Access to files beginning with. Is prohibited
if (strpos($request->path(), '/.') !== false) {
if (str_contains($request->path(), '/.')) {
return response('<h1>403 forbidden</h1>', 403);
}
/** @var Response $response */
$response = $next($request);
$response = $handler($request);
// Add cross domain HTTP header
/*$response->withHeaders([
'Access-Control-Allow-Origin' => '*',

View File

@@ -11,6 +11,11 @@ declare (strict_types=1);
// +----------------------------------------------------------------------
namespace app\index\middleware\system;
use Psr\SimpleCache\InvalidArgumentException;
use support\View;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
@@ -30,10 +35,10 @@ class IndexInitialize implements MiddlewareInterface
* @param Request $request
* @param callable $handler
* @return Response
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws InvalidArgumentException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function process(Request $request, callable $handler): Response
{
@@ -54,7 +59,7 @@ class IndexInitialize implements MiddlewareInterface
$siteInfo = saenv('site', true);
if ($siteInfo && is_array($siteInfo)) {
foreach ($siteInfo as $key => $value) {
\support\View::assign($key,$value);
View::assign($key,$value);
}
}

View File

@@ -3,6 +3,7 @@
namespace app\index\middleware\system;
use app\common\library\Auth;
use app\common\library\ResultCode;
use support\View;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
@@ -19,25 +20,25 @@ class IndexPermissions implements MiddlewareInterface
* 控制器登录鉴权
* @var bool
*/
public $needLogin = false;
public bool $needLogin = false;
/**
* 禁止登录重复
* @var array
*/
public $repeatLogin = ['login', 'register'];
public array $repeatLogin = ['login', 'register'];
/**
* 非鉴权方法
* @var array
*/
public $noNeedAuth = [];
public array $noNeedAuth = [];
/**
* 跳转URL地址
* @var string
*/
public $JumpUrl = '/user/index';
public string $JumpUrl = '/user/index';
/**
* 校验权限
@@ -67,16 +68,21 @@ class IndexPermissions implements MiddlewareInterface
// 是否验证登录器
$auth = Auth::instance();
if ($auth->isLogin()) {
$request->userId = $auth->userInfo['id'];
$request->userInfo = $auth->userInfo;
$request->user_id = $auth->userData['id'];
$request->userData = $auth->userData;
// 禁止重复登录
if (in_array($action, $this->repeatLogin)) {
return redirect($this->JumpUrl);
}
View::assign('user', $auth->userInfo);
View::assign('user', $auth->userData);
} else {
if ($this->needLogin && !in_array($action, $this->noNeedAuth)) {
return redirect('/');
if (\request()->isAjax()) {
return json(ResultCode::PLEASELOGININ);
} else {
return redirect('/user/login');
}
}
}