source: backend/Helpers/AuthorizeAttribute.cs@ 057037b

Last change on this file since 057037b was 057037b, checked in by Danilo <danilo.najkov@…>, 2 years ago

backend full

  • 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.