Exemplo n.º 1
0
        public CiResult <SiteInfoViewModel> SiteInfo()
        {
            var resultSiteInfo = service.Get <SiteInfoViewModel>(SystemSettingType.SiteInfo);

            if (resultSiteInfo.IsSuccess)
            {
                // Html Decode
                resultSiteInfo.Data.Footer = HttpUtility.HtmlDecode(resultSiteInfo.Data.Footer);
            }

            return(resultSiteInfo);
        }
Exemplo n.º 2
0
        public ActionResult ClientInfo()
        {
            var result = service.Get <ClientInfoViewModel>(SystemSettingType.ClientInfo);

            if (!result.IsSuccess)
            {
                SetAlertMessage(result.Message, AlertType.warning);
            }
            return(View(result.Data));
        }
Exemplo n.º 3
0
        public ActionResult GetSetting(string name)
        {
            var entity = SystemSettingService.Get(s => s.Name.Equals(name));

            return(ResultData(entity));
        }
Exemplo n.º 4
0
 public static SystemSettingBase Get()
 {
     return(Service.Get());
 }
Exemplo n.º 5
0
        public void Init()
        {
            #region client
            var defaultHost = ConfigurationManager.AppSettings["DefaultHost"];
            var host        = !string.IsNullOrEmpty(defaultHost) ? defaultHost : RouteHelper.HostName();
            IsLocal = !string.IsNullOrEmpty(defaultHost);

            IsApiHtml        = false;
            IsHttps          = false;
            DefaultLanguage  = LanguageType.Chinese;
            AdminLoginImage  = "default";
            MemberIndex      = "Index";
            ProfileWithEmail = false;
            ProfileWithPhone = false;
            LoginStyle       = LoginStyle.Normal;
            switch (host)
            {
            case "cms.xnet.world":    //Demo中
                                      // ClientID = new Guid("00000000-1111-2222-3333-123456789999");
                                      // ClientCode = "000";
                                      // SystemName = "Demo";

                ClientID   = new Guid("a4dde220-30e5-490b-bb5b-3c39c3abbe4f");
                ClientCode = "003";
                SystemName = "Demo";

                break;

            //拙八郎
            case "www.eightgeman.com":
                ClientID = new Guid("82092779-8fc9-47d3-adb1-7574bcddc00d");
                //ClientCode = "001";
                //SystemName = "8GeMan";
                SiteName         = "eightgeman";
                IsHttps          = true;
                MemberIndex      = "Profile";
                ProfileWithEmail = true;
                ProfileWithPhone = true;
                break;

            //滑輪
            case "www.rollersports.org.tw":
                ClientID = new Guid("524dde74-fdef-481a-b9ed-49bab41f7964");
                //ClientCode = "002";
                //SystemName = "RollerSport";
                SiteName         = "rollersports";
                IsHttps          = true;
                MemberIndex      = "Profile";
                ProfileWithEmail = true;
                ProfileWithPhone = true;
                LoginStyle       = LoginStyle.Popup;
                break;

            //迷你足球
            case "soccer.ai-sportthings.com":
            case "www.ai-sportthings.com":
                ClientID = new Guid("a4dde220-30e5-490b-bb5b-3c39c3abbe4f");
                //ClientCode = "003";
                //SystemName = "MiniSoccer";
                //SiteName = "ai-sportthings";
                IsHttps         = true;
                AdminLoginImage = "003";
                MemberIndex     = "Profile";
                break;

            default:
                break;
            }
            #endregion

            ClientService clientService = new ClientService();
            if (ClientID != Guid.Empty)
            {
                var client = clientService.Get(ClientID);
                ClientCode     = client.ClientCode;
                SystemName     = client.SystemName;
                ClientSettings = client.ClientSetting.ToContainList <ClientSetting>();
            }
            clientService.Dispose();
            _Log.CreateText("Application init " + SystemName);

            #region SetSystemSetting

            SystemSettingService service = new SystemSettingService();
            service.ClientID = ClientID;

            //SiteInfo
            var resultSiteInfo = service.Get <SiteInfoViewModel>(SystemSettingType.SiteInfo);
            if (resultSiteInfo.IsSuccess)
            {
                // Html Decode
                resultSiteInfo.Data.Footer = HttpUtility.HtmlDecode(resultSiteInfo.Data.Footer);
                SiteInfo = resultSiteInfo.Data;
            }

            //ApiKey
            var resultApiKey = service.Get <ApiKeyViewModel>(SystemSettingType.ApiKey);
            if (resultApiKey.IsSuccess)
            {
                ApiKey = resultApiKey.Data;
            }

            service.Dispose();
            #endregion
        }
Exemplo n.º 6
0
        /// <summary>
        /// 寄送郵件
        /// </summary>
        /// <param name="userID">user id</param>
        /// <param name="model">Mail內容取代字串</param>
        /// <param name="systemMailType">郵件類型</param>
        /// <param name="validType">驗證碼類型</param>
        /// <param name="structureID">郵件類型structure</param>
        /// <param name="fromFn">來源</param>
        /// <returns></returns>
        public async Task <CiResult> SendEmail(Guid userID, ReplaceMailContent model,
                                               SystemMailType systemMailType, ValidType?validType = null, Guid?structureID = null,
                                               string fromFn = "")
        {
            var result = new CiResult {
                IsSuccess = true
            };
            var mailTool = new MailTool {
                email = model.UserEmail
            };

            //ReplaceMailContent
            model.WebsiteUrl = RouteHelper.BaseUrl();
            if (string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.UserEmail) || !_Check.IsEmail(model.UserEmail))
            {
                result.IsSuccess = false;
            }

            //get setting
            if (result.IsSuccess)
            {
                var smtpResult = settingService.Get <SmtpServerViewModel>(SystemSettingType.SmtpServer);
                mailTool.setting = smtpResult.Data;
                if (!smtpResult.IsSuccess || !smtpResult.Data.IsEnabled)
                {
                    result.IsSuccess = false;
                }
            }

            if (result.IsSuccess)
            {
                var siteResult = settingService.Get <SiteInfoViewModel>(SystemSettingType.SiteInfo);
                if (siteResult.IsSuccess)
                {
                    model.WebsiteName = siteResult.Data.SiteName;
                }
                else
                {
                    result.IsSuccess = false;
                }
            }

            //create validCode
            if (result.IsSuccess && validType != null)
            {
                var validCodeResult = userService.CreateValidCode(userID, validType.Value);
                if (validCodeResult.IsSuccess)
                {
                    model.ConfirmUrl = RouteHelper.GetConfirmUrl(validType.Value, validCodeResult.Data, model.UserEmail);
                }
                else
                {
                    result.IsSuccess = false;
                }
            }

            //get template
            var template = new cms_EmailTemplate();

            if (result.IsSuccess)
            {
                template = templateService.GetByType(systemMailType, structureID);
                if (template != null)
                {
                    // ckeditor
                    template.Content = HttpUtility.HtmlDecode(template.Content);

                    // set template
                    mailTool.subject = model.ReplaceContent(template.Subject);
                    mailTool.content = model.ReplaceContent(template.Content);
                    if (!string.IsNullOrEmpty(template.TemplateBcc))
                    {
                        mailTool.bccReceiver = template.TemplateBcc.Split(',');
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    _Log.CreateText($"SendEmail no template: {systemMailType.ToString()}");
                }
            }

            //send mail (測試中:只能寄給開發者)
            if (result.IsSuccess)
            {
                if (!ApplicationHelper.IsLocal || (ApplicationHelper.IsLocal && mailTool.IsTestingMail(model.UserEmail)))
                {
                    result.IsSuccess = await mailTool.SendAsync(fromFn);
                }
                else
                {
                    _Log.CreateText($"Local not send: {mailTool.email}");
                }

                //add log
                emailService.CreateLog(new EmailViewModel
                {
                    Email = new cms_Email
                    {
                        Subject        = mailTool.subject,
                        Content        = mailTool.content,
                        SystemMailType = (int)systemMailType,
                        Status         = (int)MailStatus.Done,
                        SendTime       = DateTime.Now
                    },
                    SendUsers = new List <cms_EmailSendUser> {
                        new cms_EmailSendUser {
                            ToEmail  = model.UserEmail,
                            ToUser   = userID,
                            IsSend   = result.IsSuccess,//是否已發送
                            SendTime = DateTime.Now
                        }
                    }
                });
            }

            if (result.IsSuccess)
            {
                if (systemMailType == SystemMailType.ConfirmEmail)
                {
                    result.Message = string.Format(SystemMessage.EmailConfirm, model.UserEmail);
                }
                else if (systemMailType == SystemMailType.ForgotPassword)
                {
                    result.Message = string.Format(SystemMessage.PasswordReset, model.UserEmail);
                }
                else
                {
                    result.Message = SystemMessage.SendSuccess;
                }
            }
            else if (string.IsNullOrEmpty(result.Message))
            {
                result.Message = SystemMessage.MailServerError;
            }

            SessionManager.Captcha = "";

            return(result);
        }