예제 #1
0
        private async Task <SecuritySettingsEditDto> GetSecuritySettingsAsync()
        {
            var passwordComplexitySetting = new PasswordComplexitySetting
            {
                RequireDigit           = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireDigit),
                RequireLowercase       = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireLowercase),
                RequireNonAlphanumeric = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireNonAlphanumeric),
                RequireUppercase       = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireUppercase),
                RequiredLength         = await SettingManager.GetSettingValueAsync <int>(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequiredLength)
            };

            var defaultPasswordComplexitySetting = new PasswordComplexitySetting
            {
                RequireDigit           = Convert.ToBoolean(_settingDefinitionManager.GetSettingDefinition(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireDigit).DefaultValue),
                RequireLowercase       = Convert.ToBoolean(_settingDefinitionManager.GetSettingDefinition(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireLowercase).DefaultValue),
                RequireNonAlphanumeric = Convert.ToBoolean(_settingDefinitionManager.GetSettingDefinition(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireNonAlphanumeric).DefaultValue),
                RequireUppercase       = Convert.ToBoolean(_settingDefinitionManager.GetSettingDefinition(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequireUppercase).DefaultValue),
                RequiredLength         = Convert.ToInt32(_settingDefinitionManager.GetSettingDefinition(AbpZeroSettingNames.UserManagement.PasswordComplexity.RequiredLength).DefaultValue)
            };

            return(new SecuritySettingsEditDto
            {
                UseDefaultPasswordComplexitySettings = passwordComplexitySetting.Equals(defaultPasswordComplexitySetting),
                PasswordComplexity = passwordComplexitySetting,
                DefaultPasswordComplexity = defaultPasswordComplexitySetting,
                UserLockOut = await GetUserLockOutSettingsAsync(),
                TwoFactorLogin = await GetTwoFactorLoginSettingsAsync()
            });
        }
        public EntityChange GetEntityChange(object entity, IAbpSession abpSession, string[] propertyNames, object[] loadedState, object[] currentState, Int32[] dirtyProps)
        {
            var setting = entity as Setting;

            if (setting == null)
            {
                return(null);
            }

            var entityChange = new EntityChange
            {
                ChangeType         = EntityChangeType.Updated,
                ChangeTime         = DateTime.Now,
                EntityEntry        = entity, // [NotMapped]
                EntityId           = setting.Name + (setting.UserId != null ? "@" + setting.UserId : ""),
                EntityTypeFullName = typeof(Setting).FullName,
                TenantId           = abpSession.TenantId,
            };

            object oldValue;
            object newValue;
            var    valueIndex = Array.IndexOf(propertyNames, nameof(Setting.Value));

            if (loadedState == null)
            {
                // changed from default
                newValue = currentState[valueIndex];
                oldValue = _settingDefinitionManager.GetSettingDefinition(setting.Name)?.DefaultValue; //default
            }
            else if (dirtyProps == null)
            {
                // delete = restored to default
                newValue = $"default ({_settingDefinitionManager.GetSettingDefinition(setting.Name)?.DefaultValue})"; //default
                oldValue = loadedState[valueIndex];
            }
            else
            {
                // changed
                newValue = currentState[valueIndex];
                oldValue = loadedState[valueIndex];
            }

            var propChange = new EntityPropertyChange()
            {
                OriginalValue        = oldValue?.ToJsonString().TruncateWithPostfix(EntityPropertyChange.MaxValueLength),
                NewValue             = newValue?.ToJsonString().TruncateWithPostfix(EntityPropertyChange.MaxValueLength),
                PropertyName         = nameof(Setting.Value),
                PropertyTypeFullName = typeof(string).FullName,
                TenantId             = abpSession.TenantId,
            };

            entityChange.PropertyChanges = new List <EntityPropertyChange>()
            {
                propChange
            };

            return(entityChange);
        }
예제 #3
0
        public async Task <string> GetDefaultTimezoneAsync(SettingScopes scope, int?tenantId)
        {
            if (scope == SettingScopes.User)
            {
                if (tenantId.HasValue)
                {
                    return(await _settingManager.GetSettingValueForTenantAsync(TimingSettingNames.TimeZone, tenantId.Value));
                }

                return(await _settingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone));
            }

            if (scope == SettingScopes.Tenant)
            {
                return(await _settingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone));
            }

            if (scope == SettingScopes.Application)
            {
                var timezoneSettingDefinition = _settingDefinitionManager.GetSettingDefinition(TimingSettingNames.TimeZone);
                return(timezoneSettingDefinition.DefaultValue);
            }

            throw new Exception("Unknown scope for default timezone setting.");
        }
예제 #4
0
        private DefaultPasswordComplexityDto GetDefaultPasswordComplexitySetting()
        {
            var setting = new DefaultPasswordComplexityDto
            {
                RequiredLength = settingDefinitionManager.GetSettingDefinition(
                    StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequiredLength).DefaultValue.To <int>(),
                RequireDigit = settingDefinitionManager.GetSettingDefinition(
                    StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireDigit).DefaultValue.To <bool>(),
                RequireLowercase = settingDefinitionManager.GetSettingDefinition(
                    StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireLowercase).DefaultValue.To <bool>(),
                RequireUppercase = settingDefinitionManager.GetSettingDefinition(
                    StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireUppercase).DefaultValue.To <bool>(),
                RequireNonAlphanumeric = settingDefinitionManager.GetSettingDefinition(
                    StudioXZeroSettingNames.UserManagement.PasswordComplexity.RequireNonAlphanumeric).DefaultValue.To <bool>()
            };

            return(setting);
        }
예제 #5
0
        private async Task <SecuritySettingsEditDto> GetSecuritySettingsAsync()
        {
            var passwordComplexitySetting = await SettingManager.GetSettingValueAsync(AppSettings.Security.PasswordComplexity);

            var defaultPasswordComplexitySetting = _settingDefinitionManager.GetSettingDefinition(AppSettings.Security.PasswordComplexity).DefaultValue;

            return(new SecuritySettingsEditDto
            {
                UseDefaultPasswordComplexitySettings = passwordComplexitySetting == defaultPasswordComplexitySetting,
                PasswordComplexity = JsonConvert.DeserializeObject <PasswordComplexitySetting>(passwordComplexitySetting),
                DefaultPasswordComplexity = JsonConvert.DeserializeObject <PasswordComplexitySetting>(defaultPasswordComplexitySetting),
                UserLockOut = await GetUserLockOutSettingsAsync(),
                TwoFactorLogin = await GetTwoFactorLoginSettingsAsync()
            });
        }
예제 #6
0
        public async Task <HostSettingsEditDto> GetAllSettings()
        {
            var timezone = await SettingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone);

            var hostSettings = new HostSettingsEditDto
            {
                General = new GeneralSettingsEditDto
                {
                    WebSiteRootAddress    = await SettingManager.GetSettingValueAsync(AppSettings.General.WebSiteRootAddress),
                    WebSiteStatus         = await SettingManager.GetSettingValueAsync <bool>(AppSettings.General.WebSiteStatus),
                    AppName               = await SettingManager.GetSettingValueAsync(AppSettings.General.AppName),
                    AppLogo               = await SettingManager.GetSettingValueAsync(AppSettings.General.AppLogo),
                    AppTitleLogo          = await SettingManager.GetSettingValueAsync(AppSettings.General.AppTitleLogo),
                    Timezone              = timezone,
                    TimezoneForComparison = timezone
                },
                UserManagement = new HostUserManagementSettingsEditDto
                {
                    IsEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync <bool>(CommonFrameSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin)
                },
                Email = new EmailSettingsEditDto
                {
                    DefaultFromAddress     = await SettingManager.GetSettingValueAsync(EmailSettingNames.DefaultFromAddress),
                    DefaultFromDisplayName = await SettingManager.GetSettingValueAsync(EmailSettingNames.DefaultFromDisplayName),
                    SmtpHost                  = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.Host),
                    SmtpPort                  = await SettingManager.GetSettingValueAsync <int>(EmailSettingNames.Smtp.Port),
                    SmtpUserName              = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.UserName),
                    SmtpPassword              = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.Password),
                    SmtpDomain                = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.Domain),
                    SmtpEnableSsl             = await SettingManager.GetSettingValueAsync <bool>(EmailSettingNames.Smtp.EnableSsl),
                    SmtpUseDefaultCredentials = await SettingManager.GetSettingValueAsync <bool>(EmailSettingNames.Smtp.UseDefaultCredentials)
                }
            };
            var defaultTenantId = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.DefaultEdition);

            var passwordComplexitySetting = await SettingManager.GetSettingValueAsync(AppSettings.Security.PasswordComplexity);

            var defaultPasswordComplexitySetting = _settingDefinitionManager.GetSettingDefinition(AppSettings.Security.PasswordComplexity).DefaultValue;

            return(hostSettings);
        }
예제 #7
0
        public Task <string> GetSettingValueAsync(string name, int?tenantId, int?userId)
        {
            //1. Get the setting definition first by name.
            var settingDefinition = _settingDefinitionManager.GetSettingDefinition(name);

            if (settingDefinition == null)
            {
                throw new Exception("There is no setting defined for name: " + name);
            }

            var result = SettingStore.GetSettingOrNullAsync(tenantId, userId, name);

            var strVal = result.Result?.Value;

            if (result.Result == null)
            {
                strVal = settingDefinition.DefaultValue;
                SettingStore.CreateAsync(new SettingInfo(tenantId, userId, name, strVal));
            }

            return(Task.FromResult(strVal));
        }
        /// <inheritdoc cref="IUserConfigAppService.GetUserSettings"/>
        public async Task <UserSettingsConfigDto> GetUserSettings()
        {
            var config = new UserSettingsConfigDto
            {
                Values = new Dictionary <string, string>(),
            };

            var settings = await SettingManager.GetAllSettingValuesAsync(SettingScopes.All);

            using var scope = _iocResolver.CreateScope();
            foreach (var settingValue in settings)
            {
                if (!await _settingDefinitionManager.GetSettingDefinition(settingValue.Name)
                    .ClientVisibilityProvider
                    .CheckVisible(scope))
                {
                    continue;
                }

                config.Values.Add(settingValue.Name, settingValue.Value);
            }

            return(config);
        }
예제 #9
0
        public async Task <HostSettingsEditDto> GetAllSettings()
        {
            var timezone = await SettingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone);

            var hostSettings = new HostSettingsEditDto
            {
                General = new GeneralSettingsEditDto
                {
                    WebSiteRootAddress    = await SettingManager.GetSettingValueAsync(AppSettings.General.WebSiteRootAddress),
                    Timezone              = timezone,
                    TimezoneForComparison = timezone
                },
                TenantManagement = new TenantManagementSettingsEditDto
                {
                    AllowSelfRegistration = await SettingManager.GetSettingValueAsync <bool>(AppSettings.TenantManagement.AllowSelfRegistration),
                    IsNewRegisteredTenantActiveByDefault = await SettingManager.GetSettingValueAsync <bool>(AppSettings.TenantManagement.IsNewRegisteredTenantActiveByDefault),
                    UseCaptchaOnRegistration             = await SettingManager.GetSettingValueAsync <bool>(AppSettings.TenantManagement.UseCaptchaOnRegistration)
                },
                UserManagement = new HostUserManagementSettingsEditDto
                {
                    IsEmailConfirmationRequiredForLogin = await SettingManager.GetSettingValueAsync <bool>(AbpZeroSettingNames.UserManagement.IsEmailConfirmationRequiredForLogin)
                },
                Email = new EmailSettingsEditDto
                {
                    DefaultFromAddress     = await SettingManager.GetSettingValueAsync(EmailSettingNames.DefaultFromAddress),
                    DefaultFromDisplayName = await SettingManager.GetSettingValueAsync(EmailSettingNames.DefaultFromDisplayName),
                    SmtpHost                  = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.Host),
                    SmtpPort                  = await SettingManager.GetSettingValueAsync <int>(EmailSettingNames.Smtp.Port),
                    SmtpUserName              = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.UserName),
                    SmtpPassword              = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.Password),
                    SmtpDomain                = await SettingManager.GetSettingValueAsync(EmailSettingNames.Smtp.Domain),
                    SmtpEnableSsl             = await SettingManager.GetSettingValueAsync <bool>(EmailSettingNames.Smtp.EnableSsl),
                    SmtpUseDefaultCredentials = await SettingManager.GetSettingValueAsync <bool>(EmailSettingNames.Smtp.UseDefaultCredentials)
                }
            };

            var defaultTenantId = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.DefaultEdition);

            if (!string.IsNullOrEmpty(defaultTenantId) && (await _editionManager.FindByIdAsync(Convert.ToInt32(defaultTenantId)) != null))
            {
                hostSettings.TenantManagement.DefaultEditionId = Convert.ToInt32(defaultTenantId);
            }

            var defaultTimeZoneId = await _timeZoneService.GetDefaultTimezoneAsync(SettingScopes.Application, AbpSession.TenantId);

            if (hostSettings.General.Timezone == defaultTimeZoneId)
            {
                hostSettings.General.Timezone = string.Empty;
            }

            var passwordComplexitySetting = await SettingManager.GetSettingValueAsync(AppSettings.Security.PasswordComplexity);

            var defaultPasswordComplexitySetting = _settingDefinitionManager.GetSettingDefinition(AppSettings.Security.PasswordComplexity).DefaultValue;

            hostSettings.Security = new SecuritySettingsEditDto
            {
                UseDefaultPasswordComplexitySettings = passwordComplexitySetting == defaultPasswordComplexitySetting,
                PasswordComplexity        = JsonConvert.DeserializeObject <PasswordComplexitySetting>(passwordComplexitySetting),
                DefaultPasswordComplexity = JsonConvert.DeserializeObject <PasswordComplexitySetting>(defaultPasswordComplexitySetting)
            };

            return(hostSettings);
        }