Last change
on this file was 7a983b0, checked in by Danilo <danilo.najkov@…>, 3 years ago |
move files
|
-
Property mode
set to
100644
|
File size:
600 bytes
|
Line | |
---|
1 | namespace backend.Helpers;
|
---|
2 |
|
---|
3 | using backend.Entities;
|
---|
4 | using Microsoft.AspNetCore.Mvc;
|
---|
5 | using Microsoft.AspNetCore.Mvc.Filters;
|
---|
6 |
|
---|
7 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
---|
8 | public class AuthorizeAttribute : Attribute, IAuthorizationFilter
|
---|
9 | {
|
---|
10 | public void OnAuthorization(AuthorizationFilterContext context)
|
---|
11 | {
|
---|
12 | var user = context.HttpContext.Items["User"];
|
---|
13 | if (user == null)
|
---|
14 | {
|
---|
15 | // not logged in
|
---|
16 | context.Result = new JsonResult(new { message = "Unauthorized" }) { StatusCode = StatusCodes.Status401Unauthorized };
|
---|
17 | }
|
---|
18 | }
|
---|
19 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.