/// <summary> /// OK click handler. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check banned IP if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } // Check input fields string email = txtEmail.Text.Trim(); string result = new Validator() .NotEmpty(email, rfvEmailRequired.ErrorMessage) .MatchesCondition(txtEmail, input => input.IsValid(), GetString("general.correctemailformat")) .Result; // Try to subscribe new subscriber if (result == String.Empty) { if (DocumentID > 0) { BlogPostSubscriptionInfo bpsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(email, DocumentID); // Check for duplicity of subscriptions if ((bpsi == null) || !bpsi.SubscriptionApproved) { bpsi = new BlogPostSubscriptionInfo(); bpsi.SubscriptionPostDocumentID = DocumentID; bpsi.SubscriptionEmail = email; // Update user id for logged users (except the public users) if ((MembershipContext.AuthenticatedUser != null) && (!MembershipContext.AuthenticatedUser.IsPublic())) { bpsi.SubscriptionUserID = MembershipContext.AuthenticatedUser.UserID; } BlogPostSubscriptionInfoProvider.Subscribe(bpsi, DateTime.Now, true, true); lblInfo.Visible = true; if (bpsi.SubscriptionApproved) { lblInfo.Text = GetString("blog.subscription.beensubscribed"); Service.Resolve <ICurrentContactMergeService>().UpdateCurrentContactEmail(bpsi.SubscriptionEmail, MembershipContext.AuthenticatedUser); var blogsActivityLogger = new BlogsActivityLogger(); blogsActivityLogger.LogBlogPostSubscriptionActivity(bpsi); } else { lblInfo.Text = GetString("general.subscribed.doubleoptin"); int optInInterval = BlogHelper.GetBlogDoubleOptInInterval(SiteContext.CurrentSiteName); if (optInInterval > 0) { lblInfo.Text += "<br />" + string.Format(GetString("general.subscription_timeintervalwarning"), optInInterval); } } // Clear form after successful subscription txtEmail.Text = ""; } else { result = GetString("blog.subscription.emailexists"); } } else { result = GetString("general.invalidid"); } } if (result == String.Empty) { return; } lblError.Visible = true; lblError.Text = result; }
public void PerformAction() { // Check banned ip if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete)) { lblError.Visible = true; lblError.Text = GetString("General.BannedIP"); return; } if (OnBeforeCommentSaved != null) { OnBeforeCommentSaved(); } // Validate form string errorMessage = ValidateForm(); if (errorMessage == "") { // Check flooding when message being inserted through the LiveSite if (IsLiveSite && FloodProtectionHelper.CheckFlooding(SiteContext.CurrentSiteName, MembershipContext.AuthenticatedUser)) { lblError.Visible = true; lblError.Text = GetString("General.FloodProtection"); return; } var currentUser = MembershipContext.AuthenticatedUser; // Create new comment BlogCommentInfo bci; if (IsInsertMode) { bci = new BlogCommentInfo(); bci.CommentDate = DateTime.Now; bci.CommentPostDocumentID = mPostDocumentId; // User IP address bci.CommentInfo.IPAddress = RequestContext.UserHostAddress; // User agent bci.CommentInfo.Agent = Request.UserAgent; if (!currentUser.IsPublic()) { bci.CommentUserID = currentUser.UserID; } bci.CommentIsTrackback = false; } // Get existing comment else { bci = BlogCommentInfoProvider.GetBlogCommentInfo(mCommentId); } // Update basic comment properties if (bci != null) { // Add http:// if needed string url = txtUrl.Text.Trim(); if (url != "") { if ((!url.ToLowerCSafe().StartsWithCSafe("http://")) && (!url.ToLowerCSafe().StartsWithCSafe("https://"))) { url = "http://" + url; } } bci.CommentIsSpam = chkSpam.Checked; bci.CommentApproved = chkApproved.Checked; bci.CommentUserName = txtName.Text.Trim(); bci.CommentUrl = url; bci.CommentText = txtComments.Text.Trim(); bci.CommentUrl = bci.CommentUrl.ToLowerCSafe().Replace("javascript", "_javascript"); bci.CommentEmail = txtEmail.Text.Trim(); } if (IsInsertMode) { // Auto approve owner comments if (bci != null) { TreeNode blogNode = BlogHelper.GetParentBlog(bci.CommentPostDocumentID, false); if ((currentUser != null) && (blogNode != null)) { bool isAuthorized = BlogHelper.IsUserAuthorizedToManageComments(blogNode); if (isAuthorized) { bci.CommentApprovedByUserID = blogNode.NodeOwner; bci.CommentApproved = true; } else { // Is blog moderated ? bool moderated = ValidationHelper.GetBoolean(blogNode.GetValue("BlogModerateComments"), false); bci.CommentApprovedByUserID = 0; bci.CommentApproved = !moderated; } } } } // Perform bad words check if (!BadWordInfoProvider.CanUseBadWords(MembershipContext.AuthenticatedUser, SiteContext.CurrentSiteName)) { if (bci != null) { // Prepare columns to check Dictionary <string, int> columns = new Dictionary <string, int>(); columns.Add("CommentText", 0); columns.Add("CommentUserName", 200); // Perform bad words to check errorMessage = BadWordsHelper.CheckBadWords(bci, columns, "CommentApproved", "CommentApprovedByUserID", bci.CommentText, MembershipContext.AuthenticatedUser.UserID, () => ValidateComment(bci)); } } if (errorMessage == string.Empty) { if (bci != null) { if (!ValidateComment(bci)) { // Show error message lblError.Visible = true; lblError.Text = GetString("Blog.CommentEdit.EmptyBadWord"); } else { // Subscribe new subscriber if (chkSubscribe.Checked) { // Check for duplicate subscriptions BlogPostSubscriptionInfo bpsi = BlogPostSubscriptionInfoProvider.GetBlogPostSubscriptionInfo(txtEmail.Text, mPostDocumentId); if ((bpsi == null) || !bpsi.SubscriptionApproved) { bpsi = new BlogPostSubscriptionInfo(); bpsi.SubscriptionEmail = txtEmail.Text; bpsi.SubscriptionPostDocumentID = mPostDocumentId; bpsi.SubscriptionUserID = bci.CommentUserID; BlogPostSubscriptionInfoProvider.Subscribe(bpsi, DateTime.Now, true, true); if (bpsi.SubscriptionApproved) { LogRegistrationActivity(bpsi); } } else { errorMessage = GetString("blog.subscription.emailexists"); } } if (errorMessage == "") { // Save changes to database BlogCommentInfoProvider.SetBlogCommentInfo(bci); if (!bci.CommentApproved) { CommentSavedText = GetString("blog.comments.requiresmoderationafteraction"); } // Inform user lblInfo.Visible = true; lblInfo.Text = CommentSavedText; // Clear form when required if (mClearFormAfterSave) { txtComments.Text = ""; txtUrl.Text = ""; ctrlCaptcha.Value = ""; } LogCommentActivity(bci, PostNodeId, PostCulture); if (OnAfterCommentSaved != null) { OnAfterCommentSaved(bci); } } } } } } if (errorMessage != "") { // Show error message lblError.Visible = true; lblError.Text = errorMessage; } }