Пример #1
0
        /// <summary>
        /// Sets a user email
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="newEmail">New email</param>
        public virtual void SetEmail(Customer customer, string newEmail)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            newEmail = newEmail.Trim();
            string oldEmail = customer.Email;

            if (!CommonHelper.IsValidEmail(newEmail))
            {
                throw new NopException(_localizationService.GetResource("Account.EmailUsernameErrors.NewEmailIsNotValid"));
            }

            if (newEmail.Length > 100)
            {
                throw new NopException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailTooLong"));
            }

            var customer2 = _customerService.GetCustomerByEmail(newEmail);

            if (customer2 != null && customer.Id != customer2.Id)
            {
                throw new NopException(_localizationService.GetResource("Account.EmailUsernameErrors.EmailAlreadyExists"));
            }

            customer.Email = newEmail;
            _customerService.UpdateCustomer(customer);

            //update newsletter subscription (if required)
            if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase))
            {
                var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(oldEmail);
                if (subscriptionOld != null)
                {
                    subscriptionOld.Email = newEmail;
                    _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld);
                }
            }
        }
        public virtual void SetEmail(Customer customer, string newEmail)
        {
            Guard.NotNull(customer, nameof(customer));

            newEmail = newEmail.Trim();
            string oldEmail = customer.Email;

            if (!newEmail.IsEmail())
            {
                throw new SmartException(T("Account.EmailUsernameErrors.NewEmailIsNotValid"));
            }

            if (newEmail.Length > 100)
            {
                throw new SmartException(T("Account.EmailUsernameErrors.EmailTooLong"));
            }

            var customer2 = _customerService.GetCustomerByEmail(newEmail);

            if (customer2 != null && customer.Id != customer2.Id)
            {
                throw new SmartException(T("Account.EmailUsernameErrors.EmailAlreadyExists"));
            }

            customer.Email = newEmail;
            _customerService.UpdateCustomer(customer);

            //update newsletter subscription (if required)
            if (!String.IsNullOrEmpty(oldEmail) && !oldEmail.Equals(newEmail, StringComparison.InvariantCultureIgnoreCase))
            {
                var subscriptionOld = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(oldEmail, _storeContext.CurrentStore.Id);
                if (subscriptionOld != null)
                {
                    subscriptionOld.Email = newEmail;
                    _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscriptionOld);
                }
            }
        }
        public ActionResult Index(string webHookKey)
        {
            if (String.IsNullOrWhiteSpace(_settings.WebHookKey))
            {
                return(Content("Invalid Request."));
            }
            if (!string.Equals(_settings.WebHookKey, webHookKey, StringComparison.InvariantCultureIgnoreCase))
            {
                return(Content("Invalid Request."));
            }

            if (IsUnsubscribe())
            {
                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(FindEmail());

                if (subscription != null)
                {
                    // Do not publish unsubscribe event. Or duplicate events will occur.
                    _newsLetterSubscriptionService.DeleteNewsLetterSubscription(subscription, false);
                    return(Content("OK"));
                }
            }
            return(Content("Invalid Request."));
        }
        public ActionResult ImportCsv(FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            try
            {
                var file = Request.Files["importcsvfile"];
                if (file != null && file.ContentLength > 0)
                {
                    int count = 0;

                    using (var reader = new StreamReader(file.InputStream))
                    {
                        while (!reader.EndOfStream)
                        {
                            string   line = reader.ReadLine();
                            string[] tmp  = line.Split('\t');

                            if (tmp.Length == 2)
                            {
                                string email    = tmp[0].Trim();
                                bool   isActive = Boolean.Parse(tmp[1]);

                                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email);
                                if (subscription != null)
                                {
                                    subscription.Email  = email;
                                    subscription.Active = isActive;
                                    _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);
                                }
                                else
                                {
                                    subscription = new NewsLetterSubscription()
                                    {
                                        Active       = isActive,
                                        CreatedOnUtc = DateTime.UtcNow,
                                        Email        = email,
                                        NewsLetterSubscriptionGuid = Guid.NewGuid()
                                    };
                                    _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                                }
                                count++;
                            }
                        }
                        SuccessNotification(
                            String.Format(
                                _localizationService.GetResource(
                                    "Admin.Promotions.NewsLetterSubscriptions.ImportEmailsSuccess"), count))
                        ;
                        return(RedirectToAction("List"));
                    }
                }
                ErrorNotification("Please upload a file");
                return(RedirectToAction("List"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("List"));
            }
        }
Пример #5
0
        public ActionResult SubscribeNewsletter(string email, int languageid, bool newProduct, bool newBuyingRequest)
        {
            string result;
            bool   success = false;

            if (!CommonHelper.IsValidEmail(email))
            {
                result = _localizationService.GetResource("Newsletter.Email.Wrong");
                if (!(newProduct || newBuyingRequest))
                {
                    result += "<br />" + _localizationService.GetResource("Newsletter.Email.Select.Type");
                }
            }
            else
            {
                if (!(newProduct || newBuyingRequest))
                {
                    result = _localizationService.GetResource("Newsletter.Email.Select.Type");
                    return(Json(new
                    {
                        Success = false,
                        Result = result,
                    }));
                }
                //subscribe/unsubscribe
                email = email.Trim();

                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, languageid);
                if (subscription != null)
                {
                    if (!subscription.Active)
                    {
                        _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);
                    }
                    result = _localizationService.GetResource("Newsletter.SubscribeEmailSent");
                }
                else
                {
                    subscription = new NewsLetterSubscription()
                    {
                        NewsLetterSubscriptionGuid = Guid.NewGuid(),
                        Email             = email,
                        Active            = false,
                        CreatedOnUtc      = DateTime.UtcNow,
                        LanguageId        = languageid,
                        NewProduct        = newProduct,
                        NewBuyingRequests = newBuyingRequest
                    };
                    _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                    _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);

                    result = _localizationService.GetResource("Newsletter.SubscribeEmailSent");
                }
                success = true;
            }

            return(Json(new
            {
                Success = success,
                Result = result,
            }));
        }
Пример #6
0
        public ActionResult Subscribe(bool subscribe, string email)
        {
            string result;
            bool   success = false;

            if (!email.IsEmail())
            {
                result = _localizationService.GetResource("Newsletter.Email.Wrong");
            }
            else
            {
                //subscribe/unsubscribe
                email = email.Trim();

                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _siteContext.CurrentSite.Id);
                if (subscription != null)
                {
                    if (subscribe)
                    {
                        if (!subscription.Active)
                        {
                            _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);
                        }
                        result = _localizationService.GetResource("Newsletter.SubscribeEmailSent");
                    }
                    else
                    {
                        if (subscription.Active)
                        {
                            _workflowMessageService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id);
                        }
                        result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent");
                    }
                }
                else if (subscribe)
                {
                    subscription = new NewsLetterSubscription()
                    {
                        NewsLetterSubscriptionGuid = Guid.NewGuid(),
                        Email        = email,
                        Active       = false,
                        CreatedOnUtc = DateTime.UtcNow,
                        SiteId       = _siteContext.CurrentSite.Id
                    };
                    _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                    _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);

                    result = _localizationService.GetResource("Newsletter.SubscribeEmailSent");
                }
                else
                {
                    result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent");
                }
                success = true;
            }

            return(Json(new
            {
                Success = success,
                Result = result,
            }));
        }
Пример #7
0
        public ActionResult ImportCsv(FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNewsletterSubscribers))
            {
                return(AccessDeniedView());
            }

            try
            {
                var file = Request.Files["importcsvfile"];
                if (file != null && file.ContentLength > 0)
                {
                    int count = 0;

                    using (var reader = new StreamReader(file.InputStream))
                    {
                        while (!reader.EndOfStream)
                        {
                            string line = reader.ReadLine();
                            if (String.IsNullOrWhiteSpace(line))
                            {
                                continue;
                            }
                            string[] tmp = line.Split(',');

                            var  email    = "";
                            bool isActive = true;
                            //parse
                            if (tmp.Length == 1)
                            {
                                //"email" only
                                email = tmp[0].Trim();
                            }
                            else if (tmp.Length == 2)
                            {
                                //"email" and "active" fields specified
                                email    = tmp[0].Trim();
                                isActive = Boolean.Parse(tmp[1].Trim());
                            }
                            else
                            {
                                throw new NopException("Wrong file format");
                            }

                            //import
                            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _workContext.WorkingLanguage.Id);
                            if (subscription != null)
                            {
                                subscription.Email  = email;
                                subscription.Active = isActive;
                                _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);
                            }
                            else
                            {
                                subscription = new NewsLetterSubscription()
                                {
                                    Active       = isActive,
                                    CreatedOnUtc = DateTime.UtcNow,
                                    Email        = email,
                                    NewsLetterSubscriptionGuid = Guid.NewGuid()
                                };
                                _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                            }
                            count++;
                        }
                        SuccessNotification(String.Format(_localizationService.GetResource("Admin.Promotions.NewsLetterSubscriptions.ImportEmailsSuccess"), count));
                        return(RedirectToAction("List"));
                    }
                }
                ErrorNotification(_localizationService.GetResource("Admin.Common.UploadFile"));
                return(RedirectToAction("List"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("List"));
            }
        }
Пример #8
0
        public ActionResult Subscribe(bool subscribe, string email)
        {
            string result;
            var    success            = false;
            var    customer           = Services.WorkContext.CurrentCustomer;
            var    hasConsentedToGdpr = customer.GetAttribute <bool>(SystemCustomerAttributeNames.HasConsentedToGdpr);
            var    hasConsented       = ViewData["GdprConsent"] != null ? (bool)ViewData["GdprConsent"] : hasConsentedToGdpr;

            if (!hasConsented && _privacySettings.Value.DisplayGdprConsentOnForms)
            {
                return(Json(new
                {
                    Success = success,
                    Result = String.Empty
                }));
            }

            if (!email.IsEmail())
            {
                result = T("Newsletter.Email.Wrong");
            }
            else
            {
                // subscribe/unsubscribe
                email = email.Trim();

                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _storeContext.CurrentStore.Id);
                if (subscription != null)
                {
                    if (subscribe)
                    {
                        if (!subscription.Active)
                        {
                            Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);
                        }
                        result = T("Newsletter.SubscribeEmailSent");
                    }
                    else
                    {
                        if (subscription.Active)
                        {
                            Services.MessageFactory.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id);
                        }
                        result = T("Newsletter.UnsubscribeEmailSent");
                    }
                }
                else if (subscribe)
                {
                    subscription = new NewsLetterSubscription
                    {
                        NewsLetterSubscriptionGuid = Guid.NewGuid(),
                        Email             = email,
                        Active            = false,
                        CreatedOnUtc      = DateTime.UtcNow,
                        StoreId           = _storeContext.CurrentStore.Id,
                        WorkingLanguageId = _workContext.WorkingLanguage.Id
                    };

                    _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                    Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);

                    result = T("Newsletter.SubscribeEmailSent");
                }
                else
                {
                    result = T("Newsletter.UnsubscribeEmailSent");
                }
                success = true;
            }

            return(Json(new
            {
                Success = success,
                Result = result,
            }));
        }
        public HttpResponseMessage Subscribe(int customerid, bool subscribe, string email, int id = 0)
        {
            var response = this.Request.CreateResponse();
            var customer = _customerServices.GetCustomerById(customerid);

            if (customerid != 0)
            {
                _services.WorkContext.CurrentCustomer = customer;
            }
            string jsonString = "";

            try
            {
                string result  = "";
                var    success = false;
                if (!email.IsEmail())
                {
                    result = T("Newsletter.Email.Wrong");
                }
                else
                {
                    // subscribe/unsubscribe
                    email = email.Trim();
                    _workContext.CurrentCustomer = (customer != null) ? customer : _customerServices.GetCustomerById(id);
                    var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email, _storeContext.CurrentStore.Id);
                    if (subscription != null)
                    {
                        if (subscribe)
                        {
                            if (!subscription.Active)
                            {
                                Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);
                                result = T("Newsletter.SubscribeEmailSent");
                            }
                            else
                            {
                                result = T("Newsletter.AllReadysubscribed");
                            }
                        }
                        else
                        {
                            if (subscription.Active)
                            {
                                Services.MessageFactory.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id);
                                result = T("Newsletter.UnsubscribeEmailSent");
                            }
                            else
                            {
                                result = T("Newsletter.AllReadyunsubscribed");
                            }
                        }
                    }
                    else
                    {
                        if (subscribe)
                        {
                            subscription = new NewsLetterSubscription
                            {
                                NewsLetterSubscriptionGuid = Guid.NewGuid(),
                                Email        = email,
                                Active       = false,
                                CreatedOnUtc = DateTime.UtcNow,
                                StoreId      = _storeContext.CurrentStore.Id
                            };

                            _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                            Services.MessageFactory.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);
                            result = T("Newsletter.SubscribeEmailSent");
                        }
                        else
                        {
                            result = T("Newsletter.SubscribscribtionNotFound");
                        }
                    }
                }

                jsonString          = JsonConvert.SerializeObject(result, Formatting.None);
                jsonString          = "{\"code\":1,\"message\": \"success\",\"data\":" + jsonString + "}";
                response.StatusCode = HttpStatusCode.OK;
                response.Content    = new StringContent(jsonString, Encoding.UTF8, "application/json");
                return(response);
            }
            catch (Exception ex)
            {
                jsonString       = "{\"code\": 0,\"message\": \"" + _localizationService.GetResource("Common.SomethingWentWrong") + "\"}";
                response.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");
                return(response);
            }
        }
Пример #10
0
        public JsonResult SubscribeNewsletter(NewsletterBoxModel model)
        {
            string result;
            bool   success   = false;
            var    email     = model.Email;
            var    subscribe = model.Subscribe;

            if (!CommonHelper.IsValidEmail(email))
            {
                result = _localizationService.GetResource("Newsletter.Email.Wrong");
            }
            else
            {
                //subscribe/unsubscribe
                email = email.Trim();

                var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(email);
                if (subscription != null)
                {
                    if (subscribe)
                    {
                        if (!subscription.Active)
                        {
                            _workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingCurrency.Id);
                        }
                        result = _localizationService.GetResource("Newsletter.SubscribeEmailSent");
                    }
                    else
                    {
                        if (subscription.Active)
                        {
                            _workflowMessageService.SendNewsLetterSubscriptionDeactivationMessage(subscription, _workContext.WorkingLanguage.Id);
                        }
                        result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent");
                    }
                }
                else if (subscribe)
                {
                    subscription = new NewsLetterSubscription()
                    {
                        NewsLetterSubscriptionGuid = Guid.NewGuid(),
                        Email        = email,
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        Gender       = model.Gender,
                        Active       = true,
                        CreatedOnUtc = DateTime.UtcNow,
                        LanguageId   = _workContext.WorkingLanguage.Id
                    };
                    _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                    //_workflowMessageService.SendNewsLetterSubscriptionActivationMessage(subscription, _workContext.WorkingLanguage.Id);

                    //result = _localizationService.GetResource("Newsletter.SubscribeEmailSent");
                }
                else
                {
                    //result = _localizationService.GetResource("Newsletter.UnsubscribeEmailSent");
                }
                success = true;
            }

            return(Json(new
            {
                Success = success
            }));
        }
Пример #11
0
        public ActionResult CampaignEmailCheck(string CampaignMail)
        {
            var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(CampaignMail);

            if (subscription != null && subscription.FirstName != null && subscription.RegistrationType == "Campaign")
            {
                return(Json(_localizationService.GetResource("Campaign.Exist.MailAddress"), JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
        }
Пример #12
0
        /// <summary>
        /// Export user list to xml
        /// </summary>
        /// <param name="users">Users</param>
        /// <returns>Result in XML format</returns>
        public virtual string ExportUsersToXml(IList <User> users)
        {
            var sb           = new StringBuilder();
            var stringWriter = new StringWriter(sb);
            var xmlWriter    = new XmlTextWriter(stringWriter);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("Users");
            xmlWriter.WriteAttributeString("Version", WorkVersion.CurrentVersion);

            foreach (var user in users)
            {
                xmlWriter.WriteStartElement("User");
                xmlWriter.WriteElementString("UserId", null, user.Id.ToString());
                xmlWriter.WriteElementString("UserGuid", null, user.UserGuid.ToString());
                xmlWriter.WriteElementString("Email", null, user.Email);
                xmlWriter.WriteElementString("UserName", null, user.UserName);
                xmlWriter.WriteElementString("Password", null, user.Password);
                xmlWriter.WriteElementString("PasswordFormatId", null, user.PasswordFormatId.ToString());
                xmlWriter.WriteElementString("PasswordSalt", null, user.PasswordSalt);
                xmlWriter.WriteElementString("IsTaxExempt", null, user.IsTaxExempt.ToString());
                xmlWriter.WriteElementString("AffiliateId", null, user.AffiliateId.ToString());
                xmlWriter.WriteElementString("Active", null, user.Active.ToString());


                xmlWriter.WriteElementString("IsGuest", null, user.IsGuest().ToString());
                xmlWriter.WriteElementString("IsRegistered", null, user.IsRegistered().ToString());
                xmlWriter.WriteElementString("IsAdministrator", null, user.IsAdmin().ToString());
                xmlWriter.WriteElementString("IsForumModerator", null, user.IsForumModerator().ToString());

                xmlWriter.WriteElementString("FirstName", null, user.GetAttribute <string>(SystemUserAttributeNames.FirstName));
                xmlWriter.WriteElementString("LastName", null, user.GetAttribute <string>(SystemUserAttributeNames.LastName));
                xmlWriter.WriteElementString("Gender", null, user.GetAttribute <string>(SystemUserAttributeNames.Gender));
                xmlWriter.WriteElementString("Company", null, user.GetAttribute <string>(SystemUserAttributeNames.Company));

                xmlWriter.WriteElementString("CountryId", null, user.GetAttribute <int>(SystemUserAttributeNames.CountryId).ToString());
                xmlWriter.WriteElementString("StreetAddress", null, user.GetAttribute <string>(SystemUserAttributeNames.StreetAddress));
                xmlWriter.WriteElementString("StreetAddress2", null, user.GetAttribute <string>(SystemUserAttributeNames.StreetAddress2));
                xmlWriter.WriteElementString("ZipPostalCode", null, user.GetAttribute <string>(SystemUserAttributeNames.ZipPostalCode));
                xmlWriter.WriteElementString("City", null, user.GetAttribute <string>(SystemUserAttributeNames.City));
                xmlWriter.WriteElementString("CountryId", null, user.GetAttribute <int>(SystemUserAttributeNames.CountryId).ToString());
                xmlWriter.WriteElementString("StateProvinceId", null, user.GetAttribute <int>(SystemUserAttributeNames.StateProvinceId).ToString());
                xmlWriter.WriteElementString("Phone", null, user.GetAttribute <string>(SystemUserAttributeNames.Phone));
                xmlWriter.WriteElementString("Fax", null, user.GetAttribute <string>(SystemUserAttributeNames.Fax));
                xmlWriter.WriteElementString("VatNumber", null, user.GetAttribute <string>(SystemUserAttributeNames.VatNumber));
                xmlWriter.WriteElementString("VatNumberStatusId", null, user.GetAttribute <int>(SystemUserAttributeNames.VatNumberStatusId).ToString());
                xmlWriter.WriteElementString("TimeZoneId", null, user.GetAttribute <string>(SystemUserAttributeNames.TimeZoneId));

                var  newsletter = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmail(user.Email);
                bool subscribedToNewsletters = newsletter != null && newsletter.Active;
                xmlWriter.WriteElementString("Newsletter", null, subscribedToNewsletters.ToString());

                xmlWriter.WriteElementString("AvatarPictureId", null, user.GetAttribute <int>(SystemUserAttributeNames.AvatarPictureId).ToString());
                xmlWriter.WriteElementString("ForumPostCount", null, user.GetAttribute <int>(SystemUserAttributeNames.ForumPostCount).ToString());
                xmlWriter.WriteElementString("Signature", null, user.GetAttribute <string>(SystemUserAttributeNames.Signature));

                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Close();
            return(stringWriter.ToString());
        }