Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
723bca12
Commit
723bca12
authored
May 28, 2020
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
ac89a91e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
18 deletions
+45
-18
ApiFilterAttribute.cs
Mall.WebApi/Filter/ApiFilterAttribute.cs
+45
-18
No files found.
Mall.WebApi/Filter/ApiFilterAttribute.cs
View file @
723bca12
...
@@ -40,7 +40,9 @@ namespace Mall.WebApi.Filter
...
@@ -40,7 +40,9 @@ namespace Mall.WebApi.Filter
//请求参数
//请求参数
JObject
parm
=
new
JObject
();
JObject
parm
=
new
JObject
();
string
token
=
""
;
string
token
=
""
;
#
region
api
监控日志
parm
=
DoApiMonitorLog
(
actionContext
,
ref
token
);
parm
=
DoApiMonitorLog
(
actionContext
,
ref
token
);
#
endregion
bool
isCheckToken
=
true
;
bool
isCheckToken
=
true
;
var
endpoint
=
actionContext
.
HttpContext
.
Features
.
Get
<
IEndpointFeature
>()?.
Endpoint
;
var
endpoint
=
actionContext
.
HttpContext
.
Features
.
Get
<
IEndpointFeature
>()?.
Endpoint
;
if
(
endpoint
!=
null
&&
endpoint
.
Metadata
.
GetMetadata
<
AllowAnonymousAttribute
>()
!=
null
)
if
(
endpoint
!=
null
&&
endpoint
.
Metadata
.
GetMetadata
<
AllowAnonymousAttribute
>()
!=
null
)
...
@@ -48,6 +50,8 @@ namespace Mall.WebApi.Filter
...
@@ -48,6 +50,8 @@ namespace Mall.WebApi.Filter
isCheckToken
=
false
;
isCheckToken
=
false
;
}
}
#
region
Token
校验
#
region
Token
校验
if
(
isCheckToken
)
if
(
isCheckToken
)
...
@@ -137,26 +141,16 @@ namespace Mall.WebApi.Filter
...
@@ -137,26 +141,16 @@ namespace Mall.WebApi.Filter
JObject
parm
=
new
JObject
();
JObject
parm
=
new
JObject
();
var
request
=
actionContext
.
HttpContext
.
Request
;
var
request
=
actionContext
.
HttpContext
.
Request
;
#
region
如果参数是
json
实体对象,获取序列化后的数据
#
region
如果参数是
json
实体对象,获取序列化后的数据
request
.
EnableBuffering
();
//重置读取
request
.
Body
.
Seek
(
0
,
SeekOrigin
.
Begin
);
request
.
Body
.
Position
=
0
;
Stream
stream
=
request
.
Body
;
Encoding
encoding
=
Encoding
.
UTF8
;
if
(
request
.
ContentLength
>
0
)
if
(
request
.
ContentLength
>
0
)
{
{
string
responseData
=
""
;
byte
[]
buffer
=
new
byte
[
request
.
ContentLength
.
Value
];
string
data
=
""
;
stream
.
Read
(
buffer
,
0
,
buffer
.
Length
);
//多次读取Request.Body
string
responseData
=
Encoding
.
UTF8
.
GetString
(
buffer
);
using
(
MemoryStream
ms
=
new
MemoryStream
())
{
request
.
Body
.
CopyToAsync
(
ms
);
//设置当前流的位置为0
ms
.
Seek
(
0
,
SeekOrigin
.
Begin
);
//这里ReadToEnd执行完毕后requestBodyStream流的位置会从0到最后位置(即request.ContentLength)
data
=
new
StreamReader
(
ms
,
Encoding
.
UTF8
).
ReadToEnd
();
//设置当前流的位置为0
ms
.
Seek
(
0
,
SeekOrigin
.
Begin
);
request
.
Body
=
ms
;
StreamReader
sr
=
new
StreamReader
(
request
.
Body
);
responseData
=
sr
.
ReadToEnd
();
}
if
(!
string
.
IsNullOrWhiteSpace
(
responseData
.
Trim
()))
if
(!
string
.
IsNullOrWhiteSpace
(
responseData
.
Trim
()))
{
{
try
try
...
@@ -312,6 +306,39 @@ namespace Mall.WebApi.Filter
...
@@ -312,6 +306,39 @@ namespace Mall.WebApi.Filter
//TODO查询用户权限
//TODO查询用户权限
string
url
=
actionContext
.
HttpContext
.
Request
.
GetAbsoluteUri
();
string
url
=
actionContext
.
HttpContext
.
Request
.
GetAbsoluteUri
();
bool
havPermission
=
true
;
bool
havPermission
=
true
;
//List<object> args = new List<object>() {
// uid
//};
//根据uid 判断用户是否拥有该权限
//Type type = (Type)_obj;
//MethodInfo meth = type.GetMethod(model.Method);
//try
//{
// permission = (string)meth.Invoke(Activator.CreateInstance(type), args.ToArray());
//}
//catch
//{
//}
//if (!string.IsNullOrWhiteSpace(permission))
//{
// if (permission.ToLower().Contains(url.ToLower()))
// {
// havPermission = true;
// }
// else//判断菜单是否存在
// {
// bool systemIsExit = RbUserCache.GetSystemHasMenu(url.ToLower());
// if (!systemIsExit)
// {
// havPermission = true;
// }
// }
//}
if
(
havPermission
==
false
)
if
(
havPermission
==
false
)
{
{
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment