Example #1
0
        public void SaveTest()
        {
            ConfigService configService = new ConfigService(null);

            if (configService.emailConfig == null)
            {
                configService.emailConfig = new ConfigService.EmailConfig();
            }
            configService.emailConfig.EnableSsl             = true;
            configService.emailConfig.Host                  = "123";
            configService.emailConfig.UseDefaultCredentials = true;
            configService.emailConfig.Port                  = 456;
            configService.emailConfig.userName              = "******";
            configService.emailConfig.password              = "******";
            configFileService.Save();
            // Assert.Fail();
        }
Example #2
0
        public IActionResult DoInstall(string captcha, string config)
        {
            WebSiteConfig localWebSiteConfig = configFileService.WebConfig;
            string        path = RuntimeEnvironment.IsWindows?@"C:\morenote\WebSiteConfig.json":"/morenote/WebSiteConfig.json";

            if (localWebSiteConfig != null && localWebSiteConfig.IsAlreadyInstalled)
            {
                ResponseMessage re = new ResponseMessage()
                {
                    Ok = false, Msg = $"请设置{path}的IsAlreadyInstalled变量为false"
                };
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            string verifyCode      = HttpContext.Session.GetString("VerifyCode");
            int?   verifyCodeValid = HttpContext.Session.GetInt32("VerifyCodeValid");
            int    time            = HttpContext.Session.GetInt32("VerifyCodeTime").GetValueOrDefault(0);
            int    valid           = HttpContext.Session.GetInt32("VerifyCodeValid").GetValueOrDefault(0);

            if (valid != 1 || !UnixTimeUtil.IsValid(time, 2000))
            {
                ResponseMessage re = new ResponseMessage()
                {
                    Ok = false, Msg = "验证码过期或失效"
                };
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            //销毁验证码的标志
            HttpContext.Session.SetInt32("VerifyCodeValid", 0);
            if (string.IsNullOrEmpty(verifyCode) || string.IsNullOrEmpty(captcha) || verifyCodeValid == null || verifyCodeValid == 0)
            {
                ResponseMessage re = new ResponseMessage()
                {
                    Ok = false, Msg = "错误参数"
                };
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            else
            {
                ResponseMessage re = new ResponseMessage()
                {
                    Ok = true
                };
                WebSiteConfig webSiteConfig = JsonSerializer.Deserialize <WebSiteConfig>(config);
                //检查配置文件
                if (webSiteConfig.PostgreSql == null)
                {
                    re = new ResponseMessage()
                    {
                        Ok = false, Msg = "PostgreSql错误参数"
                    };
                    return(Json(re, MyJsonConvert.GetSimpleOptions()));
                }
                configFileService.Save(webSiteConfig, ConfigFileService.GetConfigPath());
                //登录成功
                re = new ResponseMessage()
                {
                    Ok = true
                };
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
        }