/// <summary> /// Validates From, Cc and Bcc e-mails. /// </summary> public override bool Validate() { string errorMessage = ""; if (string.IsNullOrEmpty(txtTo.Text)) { errorMessage += "<br/>" + GetString("general.requireemail"); } else if (!ValidationHelper.AreEmails(txtTo.Text.Trim())) { errorMessage += "<br/>" + GetString("dialogs.email.invalidto"); } if ((txtCc.Text.Trim() != "") && !ValidationHelper.AreEmails(txtCc.Text.Trim())) { errorMessage += "<br/>" + GetString("dialogs.email.invalidcc"); } if ((txtBcc.Text.Trim() != "") && !ValidationHelper.AreEmails(txtBcc.Text.Trim())) { errorMessage += "<br/>" + GetString("dialogs.email.invalidbcc"); } errorMessage = errorMessage.Trim(); if (errorMessage != "") { lblError.Text = errorMessage; lblError.Visible = true; plnEmailUpdate.Update(); return(false); } return(true); }
/// <summary> /// Returns true if user control is valid. /// </summary> public override bool IsValid() { if (string.IsNullOrEmpty(txtEmailInput.Text.Trim())) { return(true); } // Check if valid e-mail addresses were entered bool validEmails = (AllowMultipleAddresses ? ValidationHelper.AreEmails(txtEmailInput.Text.Trim()) : ValidationHelper.IsEmail(txtEmailInput.Text.Trim())); if (validEmails) { if (this.FieldInfo != null) { // Check regular expresion if (!string.IsNullOrEmpty(this.FieldInfo.RegularExpression)) { if (new Validator().IsRegularExp(txtEmailInput.Text.Trim(), this.FieldInfo.RegularExpression, "error").Result == "error") { this.ValidationError = this.FieldInfo.ValidationErrorMessage; return(false); } } // Check min lenght if ((this.FieldInfo.MinStringLength > 0) && (txtEmailInput.Text.Trim().Length < this.FieldInfo.MinStringLength)) { this.ValidationError = this.FieldInfo.ValidationErrorMessage; return(false); } // Check max lenght if ((this.FieldInfo.MaxStringLength > 0) && (txtEmailInput.Text.Length > this.FieldInfo.MaxStringLength)) { this.ValidationError = this.FieldInfo.ValidationErrorMessage; return(false); } } return(true); } else { this.ValidationError = GetString("EmailInput.ValidationError"); return(false); } }
private void SendDraft() { if (string.IsNullOrEmpty(txtSendDraft.Text)) { lblError.Visible = true; lblError.Text = GetString("newsletter.recipientsmissing"); } else if (!ValidationHelper.AreEmails(txtSendDraft.Text)) { lblError.Visible = true; lblError.Text = GetString("newsletter.wrongemailformat"); } else { IssueProvider.SendIssue(issueId, txtSendDraft.Text); } }
/// <summary> /// Returns true if user control is valid. /// </summary> public override bool IsValid() { if (string.IsNullOrEmpty(txtEmailInput.Text.Trim())) { return(true); } // Check if valid e-mail addresses were entered bool validEmails = (AllowMultipleAddresses ? ValidationHelper.AreEmails(txtEmailInput.Text.Trim(), EmailSeparator) : ValidationHelper.IsEmail(txtEmailInput.Text.Trim())); if (validEmails) { return(true); } ValidationError = GetString("EmailInput.ValidationError"); return(false); }
/// <summary> /// Sends issue to testing email addresses. /// </summary> /// <returns>True when everything went ok</returns> private bool SendDraft() { string draftEmails = txtSendDraft.Text.Trim(); if (String.IsNullOrEmpty(draftEmails)) { ErrorMessage = GetString("newsletter.recipientsmissing"); } else if (!ValidationHelper.AreEmails(draftEmails)) { ErrorMessage = GetString("newsletter.wrongemailformat"); } else { Service <IIssueSender> .Entry().SendAsync(IssueInfoProvider.GetIssueInfo(IssueID), draftEmails); } return(String.IsNullOrEmpty(ErrorMessage)); }
/// <summary> /// Checks whether the input is correct e-mail address (or multiple e-mail addresses). /// </summary> public override string Validate() { if (this.EnableMultipleEmails) { if (!ValidationHelper.AreEmails(this.txtEmail.Text.Trim())) { return(GetString("notifications.emailgateway.formats")); } } else { if (!ValidationHelper.IsEmail(this.txtEmail.Text.Trim())) { return(GetString("notifications.emailgateway.format")); } } return(String.Empty); }
protected void btnSend_Click(object sender, EventArgs e) { // Check field for emptyness if (string.IsNullOrEmpty(txtSendDraft.Text) || (txtSendDraft.Text.Trim().Length == 0)) { ShowError(GetString("newsletter.recipientsmissing")); } // Check e-mail address validity else if (!ValidationHelper.AreEmails(txtSendDraft.Text.Trim())) { ShowError(GetString("newsletter.wrongemailformat")); } else { Service <IIssueSender> .Entry().SendAsync((IssueInfo)EditedObject, txtSendDraft.Text.Trim()); // Close the dialog ScriptHelper.RegisterStartupScript(this, GetType(), "ClosePage", "if (CloseDialog) { CloseDialog(); }", true); } }
/// <summary> /// Returns <c>true</c> if email input is empty or has correct format. /// </summary> /// <remarks>Also returns <c>true</c> if email input contains macro and is not used on live site.</remarks>> public override bool IsValid() { const bool CHECK_LENGTH = true; string emailInput = ValidationHelper.GetString(Value, String.Empty); if (string.IsNullOrEmpty(emailInput)) { return(true); } // Check if valid e-mail addresses were entered bool isValidEmail = (AllowMultipleAddresses ? ValidationHelper.AreEmails(emailInput, EmailSeparator, CHECK_LENGTH) : ValidationHelper.IsEmail(emailInput, CHECK_LENGTH)); if (isValidEmail) { return(true); } ValidationError = GetString("EmailInput.ValidationError"); return(false); }
/// <summary> /// Save button action. /// </summary> protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e) { switch (e.CommandName.ToLower()) { case "lnksave_click": txtDisplayName.Text = txtDisplayName.Text.Trim(); txtCodeName.Text = txtCodeName.Text.Trim(); txtSubject.Text = txtSubject.Text.Trim(); // Find whether required fields are not empty string result = new Validator().NotEmpty(txtDisplayName.Text, GetString("EmailTemplate_Edit.FillDisplayNameField")) .NotEmpty(txtCodeName.Text, GetString("EmailTemplate_Edit.FillCodeNameField")) .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")) .Result; // Check validity of entered e-mails if (!String.IsNullOrEmpty(txtFrom.Text) && !ValidationHelper.AreEmails(txtFrom.Text)) { result = GetString("EmailTemplate_Edit.InvalidFrom"); } else if (!String.IsNullOrEmpty(txtBcc.Text) && !ValidationHelper.AreEmails(txtBcc.Text)) { result = GetString("EmailTemplate_Edit.InvalidBcc"); } else if (!String.IsNullOrEmpty(txtCc.Text) && !ValidationHelper.AreEmails(txtCc.Text)) { result = GetString("EmailTemplate_Edit.InvalidCc"); } if (String.IsNullOrEmpty(result)) { string siteName = null; if (this.SiteID != 0) { // Get site name for non-global templates SiteInfo site = SiteInfoProvider.GetSiteInfo(this.SiteID); if (site != null) { siteName = site.SiteName; } } // Try to get template by template name and site name EmailTemplateInfo templateInfo = EmailTemplateProvider.GetEmailTemplate(txtCodeName.Text, siteName); // Find if codename of the email template is unique for the site if ((templateInfo == null) || (templateInfo.TemplateID == this.EmailTemplateID) || ((templateInfo.TemplateSiteID == 0) && (this.SiteID > 0))) { // Get object if (templateInfo == null) { templateInfo = EmailTemplateProvider.GetEmailTemplate(this.EmailTemplateID); if (templateInfo == null) { templateInfo = new EmailTemplateInfo(); } } templateInfo.TemplateID = EmailTemplateID; templateInfo.TemplateDisplayName = txtDisplayName.Text; templateInfo.TemplateName = txtCodeName.Text; templateInfo.TemplateSubject = txtSubject.Text; templateInfo.TemplateFrom = txtFrom.Text; templateInfo.TemplateBcc = txtBcc.Text; templateInfo.TemplateCc = txtCc.Text; templateInfo.TemplateText = txtText.Text; templateInfo.TemplatePlainText = txtPlainText.Text; templateInfo.TemplateSiteID = SiteID; templateInfo.TemplateType = drpEmailType.SelectedValue; // Save (insert/update) EmailTemplateInfo object EmailTemplateProvider.SetEmailTemplate(templateInfo); // Handle redirection string redirectToUrl = "~/CMSModules/EmailTemplates/Pages/Edit.aspx?templateid=" + templateInfo.TemplateID.ToString() + "&saved=1&tabmode=" + QueryHelper.GetInteger("tabmode", 0); if (this.GlobalTemplate) { redirectToUrl += "&selectedsiteid=0"; } else if (QueryHelper.GetInteger("selectedsiteid", 0) != 0) { redirectToUrl += "&selectedsiteid=" + QueryHelper.GetInteger("selectedsiteid", 0); } else if (this.SiteID > 0) { redirectToUrl += "&siteid=" + this.SiteID; } URLHelper.Redirect(redirectToUrl); } else { lblError.Visible = true; lblError.ResourceString = "EmailTemplate_Edit.UniqueCodeName"; } } else { lblError.Visible = true; lblError.Text = result; } break; } }
/// <summary> /// Save button is clicked. /// </summary> protected void lnkSave_Click(object sender, EventArgs e) { // Check 'EditForm' permission if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm")) { RedirectToAccessDenied("cms.form", "EditForm"); } string errorMessage = null; if (formInfo != null) { if (chkSendToEmail.Checked) { // Validate form errorMessage = new Validator().NotEmpty(txtFromEmail.Text, GetString("BizFormGeneral.EmptyFromEmail")) .NotEmpty(txtToEmail.Text, GetString("BizFormGeneral.EmptyToEmail")) .NotEmpty(txtSubject.Text, GetString("BizFormGeneral.EmptyEmailSubject")).Result; // Check if to e-mail contains macro expression or e-mails separated by semicolon if (string.IsNullOrEmpty(errorMessage) && !MacroProcessor.ContainsMacro(txtToEmail.Text.Trim()) && !ValidationHelper.AreEmails(txtToEmail.Text.Trim())) { errorMessage = GetString("BizFormGeneral.EmptyToEmail"); } // Check if from e-mail contains macro expression or e-mails separated by semicolon if (string.IsNullOrEmpty(errorMessage) && !MacroProcessor.ContainsMacro(txtFromEmail.Text.Trim()) && !ValidationHelper.IsEmail(txtFromEmail.Text.Trim())) { errorMessage = GetString("BizFormGeneral.EmptyFromEmail"); } if (string.IsNullOrEmpty(errorMessage)) { formInfo.FormSendFromEmail = txtFromEmail.Text.Trim(); formInfo.FormSendToEmail = txtToEmail.Text.Trim(); formInfo.FormEmailSubject = txtSubject.Text.Trim(); formInfo.FormEmailAttachUploadedDocs = chkAttachDocs.Checked; if (chkCustomLayout.Checked) { formInfo.FormEmailTemplate = htmlEditor.ResolvedValue.Trim(); } else { formInfo.FormEmailTemplate = null; } } } else { formInfo.FormSendFromEmail = null; formInfo.FormSendToEmail = null; formInfo.FormEmailSubject = null; formInfo.FormEmailTemplate = null; txtToEmail.Text = string.Empty; txtFromEmail.Text = string.Empty; txtSubject.Text = string.Empty; chkAttachDocs.Checked = true; htmlEditor.ResolvedValue = string.Empty; } if (string.IsNullOrEmpty(errorMessage)) { try { BizFormInfoProvider.SetBizFormInfo(formInfo); ShowChangesSaved(); EnableDisableForm(formInfo.FormEmailTemplate); } catch (Exception ex) { errorMessage = ex.Message; } } if (!string.IsNullOrEmpty(errorMessage)) { ShowError(errorMessage); } } }
public void Save(bool closeOnSave) { // Check modify permission RaiseOnCheckPermissions(PERMISSION_MODIFY, this); txtDisplayName.Text = txtDisplayName.Text.Trim(); txtCodeName.Text = txtCodeName.Text.Trim(); txtSubject.Text = txtSubject.Text.Trim(); // Find whether required fields are not empty string result = new Validator().NotEmpty(txtDisplayName.Text, GetString("EmailTemplate_Edit.FillDisplayNameField")) .NotEmpty(txtCodeName.Text, GetString("EmailTemplate_Edit.FillCodeNameField")) .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename")) .Result; // Check validity of entered e-mails if (!String.IsNullOrEmpty(txtFrom.Text) && !ValidationHelper.AreEmails(txtFrom.Text)) { result = GetString("EmailTemplate_Edit.InvalidFrom"); } else if (!String.IsNullOrEmpty(txtBcc.Text) && !ValidationHelper.AreEmails(txtBcc.Text)) { result = GetString("EmailTemplate_Edit.InvalidBcc"); } else if (!String.IsNullOrEmpty(txtCc.Text) && !ValidationHelper.AreEmails(txtCc.Text)) { result = GetString("EmailTemplate_Edit.InvalidCc"); } if (String.IsNullOrEmpty(result)) { string siteName = null; if (SiteID != 0) { // Get site name for non-global templates SiteInfo site = SiteInfoProvider.GetSiteInfo(SiteID); if (site != null) { siteName = site.SiteName; } } // Try to get template by template name and site name EmailTemplateInfo templateInfo = EmailTemplateProvider.GetEmailTemplate(txtCodeName.Text, siteName); // Find if codename of the email template is unique for the site if ((templateInfo == null) || (templateInfo.TemplateID == EmailTemplateID) || ((templateInfo.TemplateSiteID == 0) && (SiteID > 0))) { bool isInsert = false; // Get object if (templateInfo == null) { templateInfo = EmailTemplateProvider.GetEmailTemplate(EmailTemplateID); if (templateInfo == null) { templateInfo = new EmailTemplateInfo(); isInsert = true; } } templateInfo.TemplateID = EmailTemplateID; templateInfo.TemplateDisplayName = txtDisplayName.Text; templateInfo.TemplateName = txtCodeName.Text; templateInfo.TemplateSubject = txtSubject.Text; templateInfo.TemplateFrom = txtFrom.Text; templateInfo.TemplateBcc = txtBcc.Text; templateInfo.TemplateCc = txtCc.Text; templateInfo.TemplateText = txtText.Text; templateInfo.TemplatePlainText = txtPlainText.Text; templateInfo.TemplateSiteID = SiteID; templateInfo.TemplateType = ValidationHelper.GetString(drpEmailType.Value, null); // Save (insert/update) EmailTemplateInfo object EmailTemplateProvider.SetEmailTemplate(templateInfo); CMSContext.EditedObject = templateInfo; if (isInsert) { pnlObjectLocking.ObjectManager.ObjectType = null; CMSObjectManager.CheckOutNewObject(this.Page); } // Handle redirection RedirectOnSave(templateInfo, closeOnSave); } else { ShowError(GetString("EmailTemplate_Edit.UniqueCodeName")); } } else { ShowError(result); } }
/// <summary> /// Save button is clicked. /// </summary> protected void lnkSave_Click(object sender, EventArgs e) { // Check 'EditForm' permission if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.form", "EditForm")) { RedirectToCMSDeskAccessDenied("cms.form", "EditForm"); } string errorMessage = ""; BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(formId); if (bfi != null) { if (chkSendToEmail.Checked) { // Validate form errorMessage = new Validator().NotEmpty(txtFromEmail.Text, GetString("BizFormGeneral.EmptyFromEmail")) .NotEmpty(txtToEmail.Text, GetString("BizFormGeneral.EmptyToEmail")) .NotEmpty(txtSubject.Text, GetString("BizFormGeneral.EmptyEmailSubject")).Result; // Check if to e-mail contains macro expression or e-mails separated by semicolon if (string.IsNullOrEmpty(errorMessage) && !MacroResolver.ContainsMacro(txtToEmail.Text.Trim()) && !ValidationHelper.AreEmails(txtToEmail.Text.Trim())) { errorMessage = GetString("BizFormGeneral.EmptyToEmail"); } // Check if from e-mail contains macro expression or e-mails separated by semicolon if (string.IsNullOrEmpty(errorMessage) && !MacroResolver.ContainsMacro(txtFromEmail.Text.Trim()) && !ValidationHelper.IsEmail(txtFromEmail.Text.Trim())) { errorMessage = GetString("BizFormGeneral.EmptyFromEmail"); } if (string.IsNullOrEmpty(errorMessage)) { bfi.FormSendFromEmail = txtFromEmail.Text.Trim(); bfi.FormSendToEmail = txtToEmail.Text.Trim(); bfi.FormEmailSubject = txtSubject.Text.Trim(); bfi.FormEmailAttachUploadedDocs = chkAttachDocs.Checked; if (chkCustomLayout.Checked) { bfi.FormEmailTemplate = htmlEditor.ResolvedValue.Trim(); } else { bfi.FormEmailTemplate = null; } } } else { bfi.FormSendFromEmail = null; bfi.FormSendToEmail = null; bfi.FormEmailSubject = null; bfi.FormEmailTemplate = null; txtToEmail.Text = ""; txtFromEmail.Text = ""; txtSubject.Text = ""; chkAttachDocs.Checked = true; htmlEditor.ResolvedValue = ""; } if (errorMessage == "") { try { BizFormInfoProvider.SetBizFormInfo(bfi); DisplayInfoMessage(GetString("General.ChangesSaved")); EnableDisableForm(bfi.FormEmailTemplate); } catch (Exception ex) { errorMessage = ex.Message; } } if (errorMessage != "") { DisplayErrorMessage(errorMessage); } } }