/// <summary> /// Sends the mail. /// </summary> /// <returns>True if the email was sent, false otherwise</returns> protected virtual bool SendMail() { MailMessage message = new MailMessage { From = new MailAddress(this._mailFrom), Body = this._mailBody, Subject = this._mailSubject, IsBodyHtml = true }; message.To.Add(this._mailTo); if (this._mailAttachmentFileName != null && File.Exists(this._mailAttachmentFileName)) { Attachment attachment = new Attachment(this._mailAttachmentFileName); message.Attachments.Add(attachment); } try { MainUtil.SendMail(message); string infoMessage = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.MailSentToMessage); Log.Info(Translate.Text(string.Format(CultureInfo.InvariantCulture, infoMessage, message.To, message.Subject)), "SendMailFromTemplate"); return(true); } catch (Exception e) { string errorMessage = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotSendMailMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, errorMessage, message.Subject, message.To)), e, "SendMailFromTemplate"); return(false); } }
/// <summary> /// Checks if the Tracker.Current object os null. /// </summary> /// <param name="tracker">The tracker.</param> /// <returns>In the context of the Runtime site, will trow a TrackingNotEnabledException; Otherwise null is returned /// in the context of the page editor.</returns> /// <exception cref="TrackingNotEnabledException">Tracker is null we are in the context of the runtime site.</exception> public static ITracker CheckForNull(this ITracker tracker) { if (tracker == null && !Sitecore.Context.PageMode.IsExperienceEditor) { throw new TrackingNotEnabledException(StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.TrackingNotEnabled)); } return(tracker); }
public ManagerResponse <UpdatePasswordResult, bool> ResetPassword(ForgotPasswordInputModel model) { Assert.ArgumentNotNull(this.CurrentStorefront, "storefront"); Assert.ArgumentNotNull(model, "inputModel"); var result = new UpdatePasswordResult { Success = true }; var getUserResponse = AccountManager.GetUser(model.Email); if (!getUserResponse.ServiceProviderResult.Success || getUserResponse.Result == null) { result.Success = false; foreach (var systemMessage in getUserResponse.ServiceProviderResult.SystemMessages) { result.SystemMessages.Add(systemMessage); } } else { try { var userIpAddress = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : string.Empty; var provisionalPassword = Membership.Provider.ResetPassword(getUserResponse.Result.UserName, string.Empty); var mailUtil = new MailUtil(); var wasEmailSent = mailUtil.SendMail(model.Subject, model.Body, model.Email, this.CurrentStorefront.SenderEmailAddress, new object(), new object[] { userIpAddress, provisionalPassword }); if (!wasEmailSent) { var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotSentEmailError); result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = message }); } } catch (Exception e) { result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = e.Message }); } } return(new ManagerResponse <UpdatePasswordResult, bool>(result, result.Success)); }
/// <summary> /// Sets the errors. /// </summary> /// <param name="result">The result.</param> public void SetErrors(ServiceProviderResult result) { this.Success = result.Success; if (result.SystemMessages.Count <= 0) { return; } var errors = result.SystemMessages; foreach (var error in errors) { var message = StorefrontManager.GetSystemMessage(error.Message); this.Errors.Add(string.IsNullOrEmpty(message) ? error.Message : message); } }
/// <summary> /// Sends the mail. /// </summary> /// <param name="templateName">Name of the template.</param> /// <param name="toEmail">To email.</param> /// <param name="fromEmail">From email.</param> /// <param name="subjectParameters">The subject parameters.</param> /// <param name="bodyParameters">The body parameters.</param> /// <returns>True if the email was sent, false otherwise</returns> public virtual bool SendMail([NotNull] string templateName, [NotNull] string toEmail, [NotNull] string fromEmail, [NotNull] object subjectParameters, [NotNull] object[] bodyParameters) { Assert.ArgumentNotNull(templateName, "templateName"); Assert.ArgumentNotNull(toEmail, "toEmail"); Assert.ArgumentNotNull(fromEmail, "fromEmail"); Assert.ArgumentNotNull(subjectParameters, "subjectParameters"); Assert.ArgumentNotNull(bodyParameters, "bodyParameters"); Item mailTemplates = StorefrontManager.CurrentStorefront.GlobalItem.Children[StorefrontConstants.KnowItemNames.Mails]; if (mailTemplates == null) { return(false); } Item mailTemplate = mailTemplates.Children[templateName]; if (mailTemplate == null) { string message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotLoadTemplateMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, message, templateName)), this); return(false); } var subjectField = mailTemplate.Fields[StorefrontConstants.KnownFieldNames.Subject]; if (subjectField == null) { string message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotFindEmailSubjectMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, message, templateName)), this); return(false); } var bodyField = mailTemplate.Fields[StorefrontConstants.KnownFieldNames.Body]; if (bodyField == null) { string message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotFindEmailBodyMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, message, templateName)), this); return(false); } var subject = string.Format(CultureInfo.InvariantCulture, subjectField.ToString(), subjectParameters); var body = string.Format(CultureInfo.InvariantCulture, bodyField.ToString(), bodyParameters); return(this.SendMail(toEmail, fromEmail, subject, body, string.Empty)); }
public JsonResult Register(RegisterUserInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, "RegisterInputModel"); RegisterBaseJsonResult result = new RegisterBaseJsonResult(); this.ValidateModel(result); if (result.HasErrors) { return(Json(result, JsonRequestBehavior.AllowGet)); } var response = this.AccountManager.RegisterUser(this.CurrentStorefront, inputModel); if (response.ServiceProviderResult.Success && response.Result != null) { var isLoggedIn = this.AccountManager.Login(CurrentStorefront, CurrentVisitorContext, response.Result.UserName, inputModel.Password, false); if (isLoggedIn) { result.Initialize(response.Result); } else { result.SetErrors(new List <string> { StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotCreateUser) }); } } else { result.SetErrors(response.ServiceProviderResult); } return(Json(result)); } catch (Exception e) { CommerceLog.Current.Error("Register", this, e); return(Json(new BaseJsonResult("Register", e), JsonRequestBehavior.AllowGet)); } }
public ActionResult ForgotPassword() { var datasource = this.Item; var subjectField = datasource.Fields[Templates.EmailSender.Fields.Subject.ToString()]; if (subjectField == null) { var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotFindEmailSubjectMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, message, datasource.TemplateName)), this); } var bodyField = datasource.Fields[Templates.EmailSender.Fields.Body.ToString()]; if (bodyField == null) { var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotFindEmailBodyMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, message, datasource.TemplateName)), this); } return(View("ForgotPassword")); }
public BaseJsonResult SwitchCurrency(string currency) { if (!string.IsNullOrWhiteSpace(currency)) { if (this.CurrentStorefront.IsSupportedCurrency(currency)) { StorefrontManager.SetCustomerCurrency(currency); _pricingManager.CurrencyChosenPageEvent(this.CurrentStorefront, currency); _cartManager.UpdateCartCurrency(this.CurrentStorefront, this.CurrentVisitorContext, currency); } else { var json = new BaseJsonResult { Success = false }; json.Errors.Add(StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.InvalidCurrencyError)); return(json); } } return(new BaseJsonResult()); }
public AddressListItemJsonResult ModifyAddress(PartyInputModelItem model) { var addresses = new List <CommerceParty>(); var userResponse = this.AccountManager.GetUser(Context.User.Name); var result = new AddressListItemJsonResult(userResponse.ServiceProviderResult); if (userResponse.ServiceProviderResult.Success && userResponse.Result != null) { var commerceUser = userResponse.Result; var customer = new CommerceCustomer { ExternalId = commerceUser.ExternalId }; var party = new CommerceParty { ExternalId = model.ExternalId, Name = model.Name, Address1 = model.Address1, City = model.City, Country = model.Country, State = model.State, ZipPostalCode = model.ZipPostalCode, PartyId = model.PartyId, IsPrimary = model.IsPrimary }; if (string.IsNullOrEmpty(party.ExternalId)) { // Verify we have not reached the maximum number of addresses supported. var numberOfAddresses = this.AllAddresses(result).Count; if (numberOfAddresses >= StorefrontManager.CurrentStorefront.MaxNumberOfAddresses) { var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.MaxAddressLimitReached); result.Errors.Add(string.Format(CultureInfo.InvariantCulture, message, numberOfAddresses)); result.Success = false; } else { party.ExternalId = Guid.NewGuid().ToString("B"); var response = this.AccountManager.AddParties(this.CurrentStorefront, customer, new List <Sitecore.Commerce.Entities.Party> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } else { var response = this.AccountManager.UpdateParties(this.CurrentStorefront, customer, new List <Sitecore.Commerce.Entities.Party> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } return(result); }
public JsonResult AddressModify(PartyInputModelItem model) { try { Assert.ArgumentNotNull(model, "model"); var validationResult = new BaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var addresses = new List <CommerceParty>(); var userResponse = this.AccountManager.GetUser(Context.User.Name); var result = new AddressListItemJsonResult(userResponse.ServiceProviderResult); if (userResponse.ServiceProviderResult.Success && userResponse.Result != null) { var commerceUser = userResponse.Result; var customer = new CommerceCustomer { ExternalId = commerceUser.ExternalId }; var party = new CommerceParty { ExternalId = model.ExternalId, Name = model.Name, Address1 = model.Address1, City = model.City, Country = model.Country, State = model.State, ZipPostalCode = model.ZipPostalCode, PartyId = model.PartyId, IsPrimary = model.IsPrimary }; if (string.IsNullOrEmpty(party.ExternalId)) { // Verify we have not reached the maximum number of addresses supported. int numberOfAddresses = this.AllAddresses(result).Count; if (numberOfAddresses >= StorefrontManager.CurrentStorefront.MaxNumberOfAddresses) { var message = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.MaxAddressLimitReached); result.Errors.Add(string.Format(CultureInfo.InvariantCulture, message, numberOfAddresses)); result.Success = false; } else { var response = this.AccountManager.AddParties(this.CurrentStorefront, customer, new List <CommerceParty> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } else { var response = this.AccountManager.UpdateParties(this.CurrentStorefront, customer, new List <CommerceParty> { party }); result.SetErrors(response.ServiceProviderResult); if (response.ServiceProviderResult.Success) { addresses = this.AllAddresses(result); } result.Initialize(addresses, null); } } return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { CommerceLog.Current.Error("AddressModify", this, e); return(Json(new BaseJsonResult("AddressModify", e), JsonRequestBehavior.AllowGet)); } }