From aef42df471c51438050ebae7e7b251427d8b2127 Mon Sep 17 00:00:00 2001 From: GZTime Date: Sun, 28 Aug 2022 06:29:55 +0800 Subject: [PATCH] fix: update config manage --- GZCTF/ClientApp/src/pages/admin/Configs.tsx | 16 ++++++++-------- GZCTF/Services/ConfigService.cs | 10 +++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/GZCTF/ClientApp/src/pages/admin/Configs.tsx b/GZCTF/ClientApp/src/pages/admin/Configs.tsx index 3aaf31fd1..79d4724a7 100644 --- a/GZCTF/ClientApp/src/pages/admin/Configs.tsx +++ b/GZCTF/ClientApp/src/pages/admin/Configs.tsx @@ -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, }) } /> @@ -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, }) } /> @@ -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, }) } /> @@ -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, }) } /> diff --git a/GZCTF/Services/ConfigService.cs b/GZCTF/Services/ConfigService.cs index 6f35b96f8..6ed5287a7 100644 --- a/GZCTF/Services/ConfigService.cs +++ b/GZCTF/Services/ConfigService.cs @@ -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; @@ -9,13 +10,16 @@ namespace CTFServer.Services; public class ConfigService : IConfigService { + private readonly ILogger logger; private readonly IConfigurationRoot? configuration; private readonly AppDbContext context; public ConfigService(AppDbContext _context, - IConfiguration _configuration) + ILogger _logger, + IConfiguration _configuration) { context = _context; + logger = _logger; configuration = _configuration as IConfigurationRoot; } @@ -74,10 +78,14 @@ private async Task SaveConfigInternal(HashSet 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); } }