public async Task <IHttpActionResult> GetProfile() { //var ctx = new TraktatData(); var user = await UserManager.FindByIdAsync(User.Identity.GetUserId <int>()); if (user == null) { return(BadRequest("Пользователь не найден.")); } var account = await _snapshotProvider.GetByRootIdAsync(user.Id); if (account == null) { return(BadRequest("Профиль пользователя не найден")); } var profile = new CurrentUserProfileModel(account); var globals = _globalsProvider.Get(); var result = new { User = profile, Globals = globals }; return(Ok(result)); }
public async Task <CurrentUserProfileModel> GetCurrentUserProfleAsync() { var cp = _httpContextAccessor.HttpContext.User; var user = await _userManager.FindByNameAsync(cp.Identity.Name); var roles = await _userManager.GetRolesAsync(user); var permissions = await _roleManager.GetRolesPermissionsAsync(roles.ToArray()); var model = new CurrentUserProfileModel() { DisplayName = user.DisplayName, PhoneNumber = user.PhoneNumber, Bio = user.Bio, UserDescription = user.UserDescription, Email = user.Email, Roles = roles, Permissions = permissions, AvatarUrl = AvatarHelper.GetSrc(user.Email), }; #if DEBUG model.IdentityName = cp.Identity.Name; model.AuthenticationType = cp.Identity.AuthenticationType; model.Claims = cp.Claims.Select(t => new IdentityClaim(t.Type, t.Value)).ToArray(); #endif return(model); }