source: resTools_backend/backend/Helpers/AuthorizeAttribute.cs

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 
1namespace backend.Helpers;
2
3using backend.Entities;
4using Microsoft.AspNetCore.Mvc;
5using Microsoft.AspNetCore.Mvc.Filters;
6
7[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
8public 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.