summaryrefslogtreecommitdiffstats
path: root/src/Controllers/BaseController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controllers/BaseController.cs')
-rw-r--r--src/Controllers/BaseController.cs30
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