/// <summary> /// 构造函数 /// </summary> /// <param name="siteSettings">站点设置</param> /// <param name="commentSettings">评论设置</param> public SiteSettingsEditModel(SiteSettings siteSettings, CommentSettings commentSettings) { if (siteSettings != null) { SiteName = siteSettings.SiteName; SiteDescription = siteSettings.SiteDescription; MainSiteRootUrl = siteSettings.MainSiteRootUrl; SearchMetaDescription = siteSettings.SearchMetaDescription; BeiAnScript = siteSettings.BeiAnScript; StatScript = siteSettings.StatScript; Links = siteSettings.Links; EnableAnonymousBrowse = siteSettings.EnableAnonymousBrowse; EnableAnonymousPosting = siteSettings.EnableAnonymousPosting; ShareToThirdDisplayType = siteSettings.ShareToThirdDisplayType; ShareDisplayIconSize = siteSettings.ShareDisplayIconSize; ShareToThirdBusiness = siteSettings.ShareToThirdBusiness; ShareToThirdIsEnabled = siteSettings.ShareToThirdIsEnabled; SearchMetaKeyWords = siteSettings.SearchMetaKeyWords; EnableSimpleHome = siteSettings.EnableSimpleHome; } if (commentSettings != null) { EnableComment = commentSettings.EnableComment; AllowAnonymousComment = commentSettings.AllowAnonymousComment; } }
public ActionResult ActivateByEmail(ActivateByEmail model) { if (string.IsNullOrEmpty(model.Token)) return Json(SiteUrls.Instance().SystemMessage()); if (!ModelState.IsValid) return Json(new StatusMessageData(StatusMessageType.Error, "验证码填写错误,发送失败")); bool isTimeout = false; long userId = Utility.DecryptTokenForValidateEmail(model.Token, out isTimeout); if (isTimeout) { return Json(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "链接已经失效", Body = "您使用的链接已经失效,请重新登陆", StatusMessageType = StatusMessageType.Hint })); } if (userId <= 0) { return Json(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "查找不到对应的用户", Body = "对不起,你访问的用户不存在", StatusMessageType = StatusMessageType.Hint })); } IUser user = userService.GetFullUser(userId); User userSaveToDB = user as User; if (user.AccountEmail != model.AccountEmail) { string errorMessage; bool isValidateEmail = Utility.ValidateEmail(model.AccountEmail, out errorMessage); if (!isValidateEmail) { Tunynet.Utilities.WebUtility.SetStatusCodeForError(Response); TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, Tunynet.Utilities.WebUtility.HtmlDecode(errorMessage)); return _ActivateByEmail(model.AccountEmail, model.Token); } userSaveToDB.AccountEmail = model.AccountEmail; userSaveToDB.IsEmailVerified = false; membershipService.UpdateUser(userSaveToDB); } //需要邮箱激活 try { System.Net.Mail.MailMessage mailMessage = EmailBuilder.Instance().RegisterValidateEmail(userSaveToDB); EmailService emailService = new EmailService(); //异步发送 if (emailService.SendAsyn(mailMessage)) { SiteSettings siteSettings = new SiteSettings(); TempData["SendEmailSucceedViewModel"] = SendEmailSucceedViewModelFactory.GetRegisterSendEmailSucceedViewModel(user.AccountEmail); return Json(SiteUrls.Instance().SendEmailSucceed()); } } catch (Exception ex) { LoggerFactory.GetLogger().Log(LogLevel.Error, ex, "创建帐号给用户发送激活邮件时发生错误"); } return Json(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "发送失败", Body = "邮件发送失败", StatusMessageType = StatusMessageType.Hint })); }
/// <summary> /// 加载Invitation模板 /// </summary> private static Dictionary <string, InvitationTemplate> LoadInvitationTemplates() { Dictionary <string, InvitationTemplate> InvitationTemplates; //回复:已修改 //mazq回复:不应该用DefaultLanguage吧 //回复:那先不修改了 ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>(); SiteSettings siteSettings = siteSettingsManager.Get(); string language = siteSettings.DefaultLanguage; string cacheKey = "InvitationTemplates::" + language; ICacheService cacheService = DIContainer.Resolve <ICacheService>(); InvitationTemplates = cacheService.Get <Dictionary <string, InvitationTemplate> >(cacheKey); if (InvitationTemplates == null) { InvitationTemplates = new Dictionary <string, InvitationTemplate>(); // Read in the file List <string> fileNames = new List <string>(); //平台级请求模板 string commonFileName = WebUtility.GetPhysicalFilePath(string.Format("~/Languages/" + language + "/InvitationTemplates.xml")); if (File.Exists(commonFileName)) { fileNames.Add(commonFileName); } //应用级请求模板 string applicationsRootDirectory = WebUtility.GetPhysicalFilePath("~/Applications/"); foreach (var applicationPath in Directory.GetDirectories(applicationsRootDirectory)) { string applicationInvitationTemplateFileName = Path.Combine(applicationPath, "Languages\\" + language + "\\InvitationTemplates.xml"); if (!File.Exists(applicationInvitationTemplateFileName)) { continue; } fileNames.Add(applicationInvitationTemplateFileName); } dynamic dModel = new ExpandoObject(); Type modelType = ((object)dModel).GetType(); foreach (string fileName in fileNames) { XmlDocument doc = new XmlDocument(); doc.Load(fileName); string typeKey; foreach (XmlNode node in doc.GetElementsByTagName("invitation")) { XmlNode attrNode = node.Attributes.GetNamedItem("invitationTypeKey"); if (attrNode == null) { continue; } typeKey = attrNode.InnerText; InvitationTemplate invitationTemplate = new InvitationTemplate(node); InvitationTemplates[typeKey] = invitationTemplate; //编译模板 Razor.Compile(invitationTemplate.UnhandledBody, modelType, typeKey); } } cacheService.Add(cacheKey, InvitationTemplates, CachingExpirationType.Stable); } return(InvitationTemplates); }