/// <summary> Submitts the new password for the associated sitecore membership account </summary> /// <param name="formid">The formid.</param> /// <param name="fields">The fields.</param> /// <param name="data">The data.</param> /// <exception cref="ValidatorException">The password information provided is incorrect.</exception> public void Execute(ID formid, AdaptedResultList fields, params object[] data) { NameValueCollection form = new NameValueCollection(); ActionHelper.FillFormData(form, fields, null); if (!string.IsNullOrEmpty(form["CreatePassword"])) { ICustomerManager <CustomerInfo> customerManager = Context.Entity.Resolve <ICustomerManager <CustomerInfo> >(); string customerId = customerManager.CurrentUser.NickName; MembershipUser membershipUser = Membership.GetUser(customerId); // Checks that the user information is correct for the user who want's to change password if (AuthenticationManager.Login(customerId, form["OldPassword"]) && !string.IsNullOrEmpty(customerId) && !string.IsNullOrEmpty(form["OldPassword"])) { // We can continue if the information is correct if (membershipUser != null) { string email = customerManager.CurrentUser.Email; if (!MainUtil.IsValidEmailAddress(email)) { email = membershipUser.Email; } if (membershipUser.ChangePassword(form["OldPassword"], form["CreatePassword"])) { var param = new { Recipient = email }; IMail mailProvider = Context.Entity.Resolve <IMail>(); mailProvider.SendMail(MailTemplateNamePasswordChanged, param, string.Empty); } } } else { throw new ValidatorException("The password information provided is incorrect."); } } }
/// <summary> /// Sends the mail. /// </summary> /// <param name="templateName">Name of the template.</param> /// <param name="parameters">The parameters.</param> /// <param name="queryString">The query string.</param> /// <exception cref="ConfigurationErrorsException"><c>The Configuration errors exception</c>.</exception> public virtual void SendMail([NotNull] string templateName, [NotNull] object parameters, [NotNull] string queryString) { Assert.ArgumentNotNull(templateName, "templateName"); Assert.ArgumentNotNull(parameters, "parameters"); Assert.ArgumentNotNull(queryString, "queryString"); GeneralSettings generalSettings = Context.Entity.GetConfiguration <GeneralSettings>(); Item templateItem = Sitecore.Context.Database.GetItem(generalSettings.MailTemplatesLink); if (templateItem == null) { return; } string templatePath = string.Format("{0}/{1}", templateItem.Paths.FullPath, templateName); Item mailTemplate = Sitecore.Context.Database.GetItem(templatePath); if (mailTemplate == null) { Log.Warn(string.Format(CouldNotLoadTemplateMessage, templatePath), this); return; } string body = mailTemplate["Body"].FormatWith(parameters); string subject = mailTemplate["Subject"].FormatWith(parameters); // Get body from external source string bodySourceId = mailTemplate["BodySource"]; Item bodySourceItem = Sitecore.Context.Database.GetItem(bodySourceId); if (bodySourceItem != null) { UrlString qs = new UrlString(queryString); string orderId = qs["orderid"]; Assert.IsNotNullOrEmpty(orderId, "Unable to send mail. Order number is null or empty."); string encryptKey = Crypto.EncryptTripleDES(orderId, EncryptKey); encryptKey = Uri.EscapeDataString(encryptKey); UrlString url = new UrlString(LinkManager.GetItemUrl(bodySourceItem)); url.Add("key", encryptKey); url.Append(new UrlString(queryString)); using (new SecurityDisabler()) { body += WebUtil.ExecuteWebPage(url.ToString()); } } // Replace relative url with absolute url string urlPrefix = "http://" + HttpContext.Current.Request.Url.Host + "/"; body = body.Replace("href=\"/", "href=\"" + urlPrefix); body = body.Replace("href='/", "href='" + urlPrefix); body = body.Replace("HREF=\"/", "href=\"" + urlPrefix); body = body.Replace("HREF='/", "href='" + urlPrefix); body = body.Replace("src=\"/", "src=\"" + urlPrefix); body = body.Replace("src='/", "src='" + urlPrefix); body = body.Replace("SRC=\"/", "src=\"" + urlPrefix); body = body.Replace("SRC='/", "src='" + urlPrefix); // Configuration.OrderGrid string from = mailTemplate["From"].FormatWith(parameters); if (!MainUtil.IsValidEmailAddress(from)) { string info = string.Format(InvalidEmailAddressMessage, from, templateName, "From"); ConfigurationErrorsException configurationErrorsException = new ConfigurationErrorsException(info); Log.Warn(configurationErrorsException.Message, configurationErrorsException, this); return; } string to = mailTemplate["To"].FormatWith(parameters); if (!MainUtil.IsValidEmailAddress(to)) { string info = string.Format(InvalidEmailAddressMessage, to, templateName, "To"); ConfigurationErrorsException configurationErrorsException = new ConfigurationErrorsException(info); Log.Warn(configurationErrorsException.Message, configurationErrorsException, this); return; } this.SendMail(to, from, subject, body, string.Empty); }