diff options
| author | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-10-19 23:41:23 +0200 |
| commit | 3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch) | |
| tree | 734ca81d7d0841d8863e3f523ebba14c282dc681 /src/Controllers/BaseController.cs | |
| download | fagprove-master.tar.xz fagprove-master.zip | |
Diffstat (limited to 'src/Controllers/BaseController.cs')
| -rw-r--r-- | src/Controllers/BaseController.cs | 30 |
1 files changed, 30 insertions, 0 deletions
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 |
