Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d6e6a46

Browse files
committed
add: authorization for all users
1 parent b6ea53f commit d6e6a46

File tree

7 files changed

+121
-36
lines changed

7 files changed

+121
-36
lines changed

‎.idea/.idea.Web-Series-API--ASP.NET/.idea/workspace.xml‎

Lines changed: 17 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using BusinessLogicLayer.Services;
2+
using System.Net;
3+
using System.Net.Http;
4+
using System.Web.Http.Controllers;
5+
using System.Web.Http.Filters;
6+
7+
namespace Web_Series_API__ASP.NET.Auth
8+
{
9+
public class PackageManagerChecker :AuthorizationFilterAttribute
10+
{
11+
public override void OnAuthorization(HttpActionContext actionContext)
12+
{
13+
var header = actionContext.Request.Headers.Authorization;
14+
if (header == null)
15+
{
16+
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,"Token not found, can't find role");
17+
}
18+
else
19+
{
20+
if (TokenService.GetLoginByToken(header.ToString()).Equals("PackageManager"))
21+
{
22+
23+
}
24+
else
25+
{
26+
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,"Token is not valid or expired");
27+
}
28+
}
29+
base.OnAuthorization(actionContext);
30+
}
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using BusinessLogicLayer.Services;
2+
using System.Net;
3+
using System.Net.Http;
4+
using System.Web.Http.Controllers;
5+
using System.Web.Http.Filters;
6+
7+
namespace Web_Series_API__ASP.NET.Auth
8+
{
9+
public class UserChecker :AuthorizationFilterAttribute
10+
{
11+
public override void OnAuthorization(HttpActionContext actionContext)
12+
{
13+
var header = actionContext.Request.Headers.Authorization;
14+
if (header == null)
15+
{
16+
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,"Token not found, can't find role");
17+
}
18+
else
19+
{
20+
if (TokenService.GetLoginByToken(header.ToString()).Equals("User"))
21+
{
22+
23+
}
24+
else
25+
{
26+
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,"Token is not valid or expired");
27+
}
28+
}
29+
base.OnAuthorization(actionContext);
30+
}
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using BusinessLogicLayer.Services;
2+
using System.Net;
3+
using System.Net.Http;
4+
using System.Web.Http.Controllers;
5+
using System.Web.Http.Filters;
6+
7+
namespace Web_Series_API__ASP.NET.Auth
8+
{
9+
public class VideoManagerChecker : AuthorizationFilterAttribute
10+
{
11+
public override void OnAuthorization(HttpActionContext actionContext)
12+
{
13+
var header = actionContext.Request.Headers.Authorization;
14+
if (header == null)
15+
{
16+
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,"Token not found, can't find role");
17+
}
18+
else
19+
{
20+
if (TokenService.GetLoginByToken(header.ToString()).Equals("VideoManager"))
21+
{
22+
23+
}
24+
else
25+
{
26+
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,"Token is not valid or expired");
27+
}
28+
}
29+
base.OnAuthorization(actionContext);
30+
}
31+
}
32+
}

‎Web-Series-API--ASP.NET/Controllers/UserController.cs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
namespace Web_Series_API__ASP.NET.Controllers
1313
{
1414
[TokenChecker]
15+
[AdminChecker]
1516
[EnableCors("*", "*", "*")]
1617
public class UserController : ApiController
1718
{
18-
[AdminChecker]
19+
1920
[Route("api/users")]
2021
[HttpGet]
2122
public HttpResponseMessage Get()
@@ -31,7 +32,6 @@ public HttpResponseMessage Get()
3132
}
3233
}
3334

34-
[AdminChecker]
3535
[Route("api/user/{id}")]
3636
[HttpGet]
3737
public HttpResponseMessage Get(int id)
@@ -47,7 +47,6 @@ public HttpResponseMessage Get(int id)
4747
}
4848
}
4949

50-
[AdminChecker]
5150
[Route("api/user/create")]
5251
[HttpPost]
5352
public HttpResponseMessage Post(UserModel user)
@@ -64,7 +63,6 @@ public HttpResponseMessage Post(UserModel user)
6463
}
6564
}
6665

67-
[AdminChecker]
6866
[Route("api/user/edit")]
6967
[HttpPut]
7068
public HttpResponseMessage Put(UserModel user)
@@ -81,7 +79,6 @@ public HttpResponseMessage Put(UserModel user)
8179
}
8280
}
8381

84-
[AdminChecker]
8582
[Route("api/user/remove/{id}")]
8683
[HttpDelete]
8784
public HttpResponseMessage Delete(int id)

‎Web-Series-API--ASP.NET/Controllers/VideoController.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
using System.Net.Http;
88
using System.Web.Http;
99
using System.Web.Http.Cors;
10+
using Web_Series_API__ASP.NET.Auth;
1011

1112
namespace Web_Series_API__ASP.NET.Controllers
1213
{
1314
public class VideoController : ApiController
1415
{
16+
[TokenChecker]
17+
[VideoManagerChecker]
1518
[EnableCors("*", "*", "*")]
1619
[Route("api/videos")]
1720
[HttpGet]

‎Web-Series-API--ASP.NET/Web-Series-API--ASP.NET.csproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@
9797
<ItemGroup>
9898
<Compile Include="App_Start\WebApiConfig.cs" />
9999
<Compile Include="Auth\AdminChecker.cs" />
100+
<Compile Include="Auth\PackageManagerChecker.cs" />
100101
<Compile Include="Auth\TokenChecker.cs" />
102+
<Compile Include="Auth\UserChecker.cs" />
103+
<Compile Include="Auth\VideoManagerChecker.cs" />
101104
<Compile Include="Controllers\AuthController.cs" />
102105
<Compile Include="Controllers\CategoryController.cs" />
103106
<Compile Include="Controllers\ExpenseController.cs" />

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /