Esempio n. 1
0
        private async Task <LoggedInUserInfoViewModel> GetLoggedInUserInfoAsync()
        {
            var userId         = User.Identity.GetUserId();
            var organizationId = User.Identity.GetOrganizationId();
            var claimsIdentity = User.Identity as ClaimsIdentity;

            var user = await _userManager.FindByIdAsync(userId);

            var permissions = await _permissionService.GetUserPermissionsAsync(userId, organizationId);

            var userInfo = new LoggedInUserInfoViewModel
            {
                HasRegistered    = true,
                Roles            = await _userManager.GetRolesAsync(userId),
                UserName         = User.Identity.Name,
                UserId           = userId,
                OrganizationName = claimsIdentity.FindFirstValue(WebApiConstants.ClaimOrganizationName),
                OrganizationId   = claimsIdentity.FindFirstValue(WebApiConstants.ClaimOrganizationId),
                FullName         = claimsIdentity.FindFirstValue(ClaimTypes.GivenName),
                Permissions      = permissions,
                Impersonated     = claimsIdentity?.Claims.Any(c => c.Type == WebApiConstants.ClaimUserImpersonation && c.Value == true.ToString()) ?? false,
                CultureCode      = user.CultureCode,
                TimeZone         = user.TimeZone,
                PictureId        = user.PictureId
            };

            return(userInfo);
        }