summaryrefslogtreecommitdiffstats
path: root/src/Controllers/BaseController.cs
blob: c90bfb4b9c0fb08dde7eb98d381b558720bf0dcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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; }
        }
    }
}