From 3f4c0720e1e3421431e7baa20882a4a4512a7fab Mon Sep 17 00:00:00 2001 From: ivar Date: Sun, 19 Oct 2025 23:41:23 +0200 Subject: Initial --- src/Controllers/BaseController.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Controllers/BaseController.cs (limited to 'src/Controllers/BaseController.cs') diff --git a/src/Controllers/BaseController.cs b/src/Controllers/BaseController.cs new file mode 100644 index 0000000..c90bfb4 --- /dev/null +++ b/src/Controllers/BaseController.cs @@ -0,0 +1,30 @@ +using System; +using System.Security.Claims; +using IOL.Fagprove.Data.Enums; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using IOL.Fagprove.Utilities; + +namespace IOL.Fagprove.Controllers +{ + [Authorize] + [Produces(("application/json"))] + [ApiController] + [Route("api/[controller]")] + public class BaseController : ControllerBase + { + public LoggedInUserModel LoggedInUser => new LoggedInUserModel + { + Id = User.GetClaimValue(ClaimTypes.NameIdentifier).ToGuid(), + Name = User.GetClaimValue(ClaimTypes.Name), + Role = User.GetClaimValue(ClaimTypes.Role).ToUserRole() + }; + + public class LoggedInUserModel + { + public Guid Id { get; set; } + public string Name { get; set; } + public UserRole Role { get; set; } + } + } +} \ No newline at end of file -- cgit v1.3