Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EduSpider
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
viitto
EduSpider
Commits
fa300548
Commit
fa300548
authored
May 26, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
4676ab69
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
207 additions
and
2 deletions
+207
-2
BaseController.cs
EduSpider.WebApi/Controllers/Base/BaseController.cs
+21
-1
StuController.cs
EduSpider.WebApi/Controllers/Student/StuController.cs
+57
-0
ActionFilterAttribute.cs
EduSpider.WebApi/Filter/ActionFilterAttribute.cs
+127
-0
Startup.cs
EduSpider.WebApi/Startup.cs
+2
-1
No files found.
EduSpider.WebApi/Controllers/Base/BaseController.cs
View file @
fa300548
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
System
;
using
VTX.FW.Helper
;
using
VTX.FW.VtController
;
using
VTX.FW.VtController
;
namespace
EduSpider.WebApi.Controllers.Base
namespace
EduSpider.WebApi.Controllers.Base
...
@@ -9,6 +11,24 @@ namespace EduSpider.WebApi.Controllers.Base
...
@@ -9,6 +11,24 @@ namespace EduSpider.WebApi.Controllers.Base
[
ApiController
]
[
ApiController
]
public
class
BaseController
:
ApiBaseController
public
class
BaseController
:
ApiBaseController
{
{
/// <summary>
/// 获取用户编号
/// </summary>
public
int
BaseUserId
{
get
{
int
UserId
=
0
;
if
(!
string
.
IsNullOrEmpty
(
base
.
RequestParm
.
Token
))
{
var
jObj
=
VTX
.
FW
.
Helper
.
JwtHelper
.
AnalysisToken
(
base
.
RequestParm
.
Token
);
if
(
jObj
!=
null
)
{
UserId
=
jObj
.
GetInt
(
"BaseUserId"
);
}
}
return
UserId
;
}
}
}
}
}
}
EduSpider.WebApi/Controllers/
Course
Controller.cs
→
EduSpider.WebApi/Controllers/
Student/Stu
Controller.cs
View file @
fa300548
using
EduSpider.IServices
;
using
EduSpider.IServices
;
using
EduSpider.WebApi.Controllers.Base
;
using
EduSpider.WebApi.Controllers.Base
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Cors
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
VTX.FW.Api
;
using
VTX.FW.Api
;
using
VTX.FW.Attr
;
using
VTX.FW.Attr
;
using
VTX.FW.Helper
;
namespace
EduSpider.WebApi.Controllers
namespace
EduSpider.WebApi.Controllers
{
{
/// <summary>
/// <summary>
///
课程
控制器
///
学员相关信息
控制器
/// </summary>
/// </summary>
public
class
StuController
:
BaseController
public
class
CourseController
:
BaseController
{
{
/// <summary>
/// <summary>
/// 课程仓储接口
/// 课程仓储接口
...
@@ -20,19 +21,37 @@ namespace EduSpider.WebApi.Controllers
...
@@ -20,19 +21,37 @@ namespace EduSpider.WebApi.Controllers
public
ICourseService
CourseService
{
get
;
set
;
}
public
ICourseService
CourseService
{
get
;
set
;
}
/// <summary>
/// <summary>
/// 获取课程列表
/// 获取
学员
课程列表
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
[
HttpPost
]
[
HttpPost
]
[
HttpGet
]
[
HttpGet
]
public
ApiResult
GetStuCourse
()
public
ApiResult
GetCoursePage
()
{
{
var
query
=
new
Model
.
Query
.
CourseQuery
()
{
StuIds
=
"1976394"
};
var
query
=
new
Model
.
Query
.
CourseQuery
()
{
StuIds
=
base
.
BaseUserId
.
ToString
()
};
var
list
=
CourseService
.
GetStuCourseList
(
query
);
var
list
=
CourseService
.
GetStuCourseList
(
query
);
query
.
StuIds
=
"23067080"
;
return
ApiResult
.
Success
(
data
:
list
);
}
/// <summary>
/// 获取学员作业和考试信息
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
HttpGet
]
public
ApiResult
GetStuWork
()
{
var
query
=
new
Model
.
Query
.
CourseQuery
()
{
StuIds
=
base
.
BaseUserId
.
ToString
(),
courseId
=
base
.
ReqParameters
.
GetInt
(
"courseId"
)
};
var
homeworkExamList
=
CourseService
.
GetStuWorkAndExamList
(
query
);
var
homeworkExamList
=
CourseService
.
GetStuWorkAndExamList
(
query
);
return
ApiResult
.
Success
(
data
:
homeworkExamList
,
message
:
"成功!"
);
return
ApiResult
.
Success
(
data
:
homeworkExamList
);
}
}
}
}
}
}
EduSpider.WebApi/Filter/ActionFilterAttribute.cs
0 → 100644
View file @
fa300548
using
JWT.Exceptions
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Http.Features
;
using
Microsoft.AspNetCore.Mvc.Filters
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.IO
;
using
System.Net
;
using
System.Text
;
using
System.Threading.Tasks
;
using
VTX.FW.Api
;
using
VTX.FW.Filter
;
using
VTX.FW.Helper
;
namespace
Edu.WebApi.Filter
{
/// <summary>
/// Api过滤属性
/// </summary>
public
class
ActionFilterAttribute
:
ApiFilterAttribute
{
/// <summary>
/// token验证
/// </summary>
/// <param name="actionContext"></param>
public
override
void
OnActionExecuting
(
ActionExecutingContext
actionContext
)
{
base
.
OnActionExecuting
(
actionContext
);
HttpRequest
request
=
actionContext
.
HttpContext
.
Request
;
request
.
EnableBuffering
();
RequestParm
requestParm
=
new
RequestParm
{
Token
=
request
.
Headers
[
"Authorization"
]
};
bool
isCheckToken
=
true
;
var
endpoint
=
actionContext
.
HttpContext
.
Features
.
Get
<
IEndpointFeature
>()?.
Endpoint
;
if
(
endpoint
!=
null
&&
endpoint
.
Metadata
.
GetMetadata
<
AllowAnonymousAttribute
>()
!=
null
)
{
isCheckToken
=
false
;
}
string
token
=
requestParm
.
Token
.
Replace
(
"Bearer"
,
""
).
Trim
();
//Token校验
if
(
isCheckToken
)
{
JWTValidat
(
actionContext
,
token
);
}
}
/// <summary>
/// token校验
/// </summary>
/// <param name="actionContext"></param>
/// <param name="token"></param>
private
static
void
JWTValidat
(
ActionExecutingContext
actionContext
,
string
token
)
{
if
(!
string
.
IsNullOrEmpty
(
token
))
{
//解析token,校验是否失效
try
{
JObject
jwtJson
=
VTX
.
FW
.
Helper
.
JwtHelper
.
AnalysisToken
(
token
);
var
BaseUserId
=
jwtJson
.
GetInt
(
"BaseUserId"
);
if
(
BaseUserId
>
0
)
{
var
cacheUser
=
EduSpider
.
Cache
.
User
.
UserReidsCache
.
GetUserLoginInfo
(
BaseUserId
);
if
((
cacheUser
.
Token
!=
token
||
string
.
IsNullOrWhiteSpace
(
cacheUser
.
Token
)))
{
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
{
Code
=
(
int
)
ResultCode
.
TokenOverdue
,
Message
=
"用户凭证失效,请重新登录0"
,
Data
=
null
});
}
}
}
catch
(
SignatureVerificationException
sve
)
{
string
message
=
sve
.
Message
;
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
{
Code
=
(
int
)
ResultCode
.
TokenOverdue
,
Message
=
"用户凭证失效,请重新登录1"
,
Data
=
null
});
}
catch
(
ArgumentException
ae
)
{
string
message
=
ae
.
Message
;
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
{
Code
=
(
int
)
ResultCode
.
TokenIllegal
,
Message
=
"用户凭证失效,请重新登录2"
,
Data
=
""
});
}
catch
(
Exception
ex
)
{
VTX
.
FW
.
Helper
.
LogHelper
.
WriteError
(
"JWTValidat3"
,
ex
:
ex
);
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
HttpStatusCode
.
OK
,
new
ApiResult
{
Code
=
(
int
)
ResultCode
.
TokenIllegal
,
Message
=
"用户凭证失效,请重新登录3"
,
Data
=
""
});
}
}
else
{
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
{
Code
=
(
int
)
ResultCode
.
TokenIllegal
,
Message
=
"用户凭证为空,请重新登录4"
,
Data
=
""
});
}
}
}
}
\ No newline at end of file
EduSpider.WebApi/Startup.cs
View file @
fa300548
using
Autofac
;
using
Autofac
;
using
Edu.WebApi.Filter
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Mvc.Controllers
;
using
Microsoft.AspNetCore.Mvc.Controllers
;
...
@@ -43,7 +44,7 @@ namespace EduSpider.WebApi
...
@@ -43,7 +44,7 @@ namespace EduSpider.WebApi
services
.
AddMvc
(
options
=>
services
.
AddMvc
(
options
=>
{
{
options
.
Filters
.
Add
<
ApiExceptionFilterAttribute
>();
options
.
Filters
.
Add
<
ApiExceptionFilterAttribute
>();
options
.
Filters
.
Add
<
A
pi
FilterAttribute
>();
options
.
Filters
.
Add
<
A
ction
FilterAttribute
>();
});
});
//处理josn格式
//处理josn格式
...
...
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