Skip to content

Commit

Permalink
fix: update config manage
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Aug 27, 2022
1 parent 060da39 commit aef42df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 8 additions & 8 deletions GZCTF/ClientApp/src/pages/admin/Configs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ const Configs: FC = () => {
label={SwitchLabel('允许新用户注册', '是否允许用户注册新账户')}
onChange={(e) =>
updateConfig({
...configs,
accoutPolicy: {
allowRegister: e.target.checked,
...configs?.accoutPolicy,
allowRegister: e.currentTarget.checked,
},
...configs,
})
}
/>
Expand All @@ -63,11 +63,11 @@ const Configs: FC = () => {
label={SwitchLabel('需要邮箱确认', '用户注册、更换邮箱、找回密码是否需要邮件确认')}
onChange={(e) =>
updateConfig({
...configs,
accoutPolicy: {
emailConfirmationRequired: e.target.checked,
...configs?.accoutPolicy,
emailConfirmationRequired: e.currentTarget.checked,
},
...configs,
})
}
/>
Expand All @@ -77,11 +77,11 @@ const Configs: FC = () => {
label={SwitchLabel('注册后自动激活', '是否在新用户注册后自动激活账户')}
onChange={(e) =>
updateConfig({
...configs,
accoutPolicy: {
activeOnRegister: e.target.checked,
...configs?.accoutPolicy,
activeOnRegister: e.currentTarget.checked,
},
...configs,
})
}
/>
Expand All @@ -91,11 +91,11 @@ const Configs: FC = () => {
label={SwitchLabel('使用谷歌验证码', '是否在用户发送验证邮件时检查谷歌验证码有效性')}
onChange={(e) =>
updateConfig({
...configs,
accoutPolicy: {
useGoogleRecaptcha: e.target.checked,
...configs?.accoutPolicy,
useGoogleRecaptcha: e.currentTarget.checked,
},
...configs,
})
}
/>
Expand Down
10 changes: 9 additions & 1 deletion GZCTF/Services/ConfigService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel;
using CTFServer.Models.Data;
using CTFServer.Services.Interface;
using CTFServer.Utils;
using Microsoft.EntityFrameworkCore;
using NPOI.SS.Formula.Functions;
using YamlDotNet.Core.Tokens;
Expand All @@ -9,13 +10,16 @@ namespace CTFServer.Services;

public class ConfigService : IConfigService
{
private readonly ILogger<ConfigService> logger;
private readonly IConfigurationRoot? configuration;
private readonly AppDbContext context;

public ConfigService(AppDbContext _context,
IConfiguration _configuration)
ILogger<ConfigService> _logger,
IConfiguration _configuration)
{
context = _context;
logger = _logger;
configuration = _configuration as IConfigurationRoot;
}

Expand Down Expand Up @@ -74,10 +78,14 @@ private async Task SaveConfigInternal(HashSet<Config> configs, CancellationToken
if (dbConfigs.TryGetValue(conf.ConfigKey, out var dbConf))
{
if (dbConf.Value != conf.Value)
{
dbConf.Value = conf.Value;
logger.SystemLog($"更新全局设置:{conf.ConfigKey} => {conf.Value}", TaskStatus.Success, LogLevel.Debug);
}
}
else
{
logger.SystemLog($"添加全局设置:{conf.ConfigKey} => {conf.Value}", TaskStatus.Success, LogLevel.Debug);
await context.Configs.AddAsync(conf, token);
}
}
Expand Down

0 comments on commit aef42df

Please sign in to comment.