Last change
on this file since 899b19d was 7a983b0, checked in by Danilo <danilo.najkov@…>, 3 years ago |
move files
|
-
Property mode
set to
100644
|
File size:
600 bytes
|
Rev | Line | |
---|
[b66b3ac] | 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 | {
|
---|
[057037b] | 12 | var user = context.HttpContext.Items["User"];
|
---|
[b66b3ac] | 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.