Beispiel #1
0
        public async Task <GetProfilePictureOutput> GetProfilePicture()
        {
            var userAccount = await _accountCache.GetAsync(AbpSession.GetUserId());

            if (userAccount == null || userAccount.ProfilePictureId <= 0)
            {
                return(new GetProfilePictureOutput(string.Empty));
            }

            return(await GetProfilePictureById(userAccount.ProfilePictureId));
        }
Beispiel #2
0
        public async Task <GetUserForEditOutput> GetUserForEdit([FromQuery] NullableIdDto <long> input)
        {
            //Getting all available roles
            var userRoleDtos = (await _roleManager.Roles
                                .OrderBy(r => r.DisplayName)
                                .Select(r => new UserRoleDto
            {
                RoleId = r.Id,
                RoleName = r.Name,
                RoleDisplayName = r.DisplayName
            })
                                .ToArrayAsync());

            var output = new GetUserForEditOutput
            {
                Roles = userRoleDtos
            };

            if (!input.Id.HasValue)
            {
                //Creating a new user
                output.User = new UserEditDto
                {
                    IsActive = true,
                    ShouldChangePasswordOnNextLogin = true,
                    IsTwoFactorEnabled = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.TwoFactorLogin.IsEnabled),
                    IsLockoutEnabled   = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.UserLockOut.IsEnabled)
                };

                foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync())
                {
                    var defaultUserRole = userRoleDtos.FirstOrDefault(ur => ur.RoleName == defaultRole.Name);
                    if (defaultUserRole != null)
                    {
                        defaultUserRole.IsAssigned = true;
                    }
                }
            }
            else
            {
                //Editing an existing user
                var user = await UserManager.GetUserByIdAsync(input.Id.Value);

                var account = await _accountCache.GetAsync(user.Id);

                output.User             = ObjectMapper.Map <UserEditDto>(user);
                output.ProfilePictureId = account.ProfilePictureId;

                await UserManager.UserStore.UserRepository.EnsureCollectionLoadedAsync(user, u => u.Logins);

                output.ExternalLogins = user.Logins.Select(l =>
                {
                    return(l.MapTo <ExternalUserLoginDto>());
                }).ToArray();

                foreach (var userRoleDto in userRoleDtos)
                {
                    userRoleDto.IsAssigned = await UserManager.IsInRoleAsync(user, userRoleDto.RoleName);
                }

                output.Permissions = await this.GetUserPermissionsForEdit(new EntityDto <long>(user.Id));
            }

            return(output);
        }