From 58ef5833b3f77f321c587dd86448c888029016ce Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Thu, 22 Dec 2022 14:44:26 +0100 Subject: feat: Many things - Working Login/Logout - Groundwork for web components - Loading web-components with version tag - Load temporal-polyfill globally --- code/api/Models/LoggedInUserModel.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 code/api/Models/LoggedInUserModel.cs (limited to 'code/api/Models/LoggedInUserModel.cs') diff --git a/code/api/Models/LoggedInUserModel.cs b/code/api/Models/LoggedInUserModel.cs new file mode 100644 index 0000000..9d9b944 --- /dev/null +++ b/code/api/Models/LoggedInUserModel.cs @@ -0,0 +1,31 @@ +namespace I2R.Storage.Api.Models; + +public class LoggedInUserModel +{ + public LoggedInUserModel() { } + + public LoggedInUserModel(ClaimsPrincipal user) { + Username = user.FindFirstValue(AppClaims.USERNAME); + Id = user.FindFirstValue(AppClaims.USER_ID).AsGuid(); + Role = UserRole.FromString(user.FindFirstValue(AppClaims.USER_ROLE)); + } + + public string Username { get; set; } + public Guid Id { get; set; } + public EUserRole Role { get; set; } + + public class Public + { + public string Id { get; set; } + public string Username { get; set; } + public string Role { get; set; } + } + + public static Public ForThePeople(HttpContext httpContext) { + return new Public() { + Id = httpContext.User.FindFirstValue(AppClaims.USER_ID), + Username = httpContext.User.FindFirstValue(AppClaims.USERNAME), + Role = httpContext.User.FindFirstValue(AppClaims.USER_ROLE) + }; + } +} \ No newline at end of file -- cgit v1.3