Skip to content

Commit 8380caa

Browse files
author
zhaoxiang
committed
Merge branch 'master' of gitee.com:apiadmin/ApiAdmin
2 parents 89199a2 + d826543 commit 8380caa

File tree

6 files changed

+43
-44
lines changed

6 files changed

+43
-44
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Zhao
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LICENSE.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

app/controller/admin/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function buildSuccess(array $data = [], string $msg = '操作成功', int
5757
* @author zhaoxiang <zhaoxiang051405@gmail.com>
5858
*/
5959
public function updateUserInfo(array $data, bool $isDetail = false): void {
60-
$apiAuth = $this->request->header('apiAuth');
60+
$apiAuth = $this->request->header('Api-Auth');
6161
if ($isDetail) {
6262
AdminUserData::update($data, ['uid' => $this->userInfo['id']]);
6363
$this->userInfo['userData'] = (new AdminUserData())->where('uid', $this->userInfo['id'])->find();

app/controller/admin/InterfaceList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ public function del(): Response {
150150
$rule->app_api = implode(',', $appApiArr);
151151

152152
$appApiShowArrOld = json_decode($rule->app_api_show, true);
153-
$appApiShowArr = $appApiShowArrOld[$oldInfo->groupHash];
153+
$appApiShowArr = $appApiShowArrOld[$oldInfo->group_hash];
154154
$appApiShowIndex = array_search($hash, $appApiShowArr);
155155
array_splice($appApiShowArr, $appApiShowIndex, 1);
156-
$appApiShowArrOld[$oldInfo->groupHash] = $appApiShowArr;
156+
$appApiShowArrOld[$oldInfo->group_hash] = $appApiShowArr;
157157
$rule->app_api_show = json_encode($appApiShowArrOld);
158158

159159
$rule->save();

app/middleware/AdminPermission.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class AdminPermission {
2323
*/
2424
public function handle($request, \Closure $next): Response {
2525
$userInfo = $request->API_ADMIN_USER_INFO;
26-
27-
if (!$this->checkAuth($userInfo['id'], $request->pathinfo())) {
26+
// rule里包含了rule(路由规则), ruoter(完整路由)
27+
if (!$this->checkAuth($userInfo['id'], $request->rule()->getRule())) {
2828
return json([
2929
'code' => ReturnCode::INVALID,
3030
'msg' => '非常抱歉,您没有权限这么做!',

app/middleware/ApiAuth.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ class ApiAuth {
2323
*/
2424
public function handle($request, \Closure $next) {
2525
$header = config('apiadmin.CROSS_DOMAIN');
26-
$apiHash = substr($request->pathinfo(), 4);
26+
27+
$pathParam = [];
28+
$pathArr = explode('/', $request->pathinfo());
29+
$pathArrLen = count($pathArr);
30+
for ($index = 0; $index < $pathArrLen; $index += 2) {
31+
if ($index + 1 < $pathArrLen) {
32+
$pathParam[$pathArr[$index]] = $pathArr[$index + 1];
33+
}
34+
}
35+
$apiHash = $pathParam['api'];
2736

2837
if ($apiHash) {
2938
$cached = Cache::has('ApiInfo:' . $apiHash);
@@ -53,12 +62,13 @@ public function handle($request, \Closure $next) {
5362

5463
$accessToken = $request->header('Access-Token', '');
5564
if (!$accessToken) {
56-
if ($apiInfo['method'] == 2) {
57-
$accessToken = $request->get('Access-Token', '');
58-
}
59-
if ($apiInfo['method'] == 1) {
60-
$accessToken = $request->post('Access-Token', '');
61-
}
65+
$accessToken = $request->post('Access-Token', '');
66+
}
67+
if (!$accessToken) {
68+
$accessToken = $request->get('Access-Token', '');
69+
}
70+
if (!$accessToken && !empty($pathParam['Access-Token'])) {
71+
$accessToken = $pathParam['Access-Token'];
6272
}
6373
if (!$accessToken) {
6474
return json([

0 commit comments

Comments
 (0)