コード例 #1
0
        public bool SendMailConfirmUnsubscribe(string email)
        {
            // Controllo che la mail inserita sia presente tra i contatti
            List <CommunicationEmailRecord> listaCommunicationEmail = (from m in _emailrepository.Table
                                                                       where m.Email.Equals(email)
                                                                       select m).ToList();

            if (listaCommunicationEmail == null)
            {
                _orchardServices.Notifier.Error(T("Email not found!"));
                return(false);
            }

            // Create Nonce
            string   parametri = "Email=" + email + "&Guid=" + Guid.NewGuid().ToString();
            TimeSpan delay     = new TimeSpan(1, 0, 0);
            string   Nonce     = _commonServices.CreateNonce(parametri, delay);

            // Update CommunicationEmailRecord - Save Nonce
            foreach (CommunicationEmailRecord recordMail in listaCommunicationEmail)
            {
                recordMail.KeyUnsubscribe = Nonce;
                _emailrepository.Update(recordMail);
            }

            // Encode Nonce
            string parametriEncode = System.Web.HttpUtility.HtmlEncode(Nonce.Replace('+', '_').Replace('/', '-'));

            string host = string.Format("{0}://{1}{2}",
                                        _orchardServices.WorkContext.HttpContext.Request.Url.Scheme,
                                        _orchardServices.WorkContext.HttpContext.Request.Url.Host,
                                        _orchardServices.WorkContext.HttpContext.Request.Url.Port == 80 ? string.Empty : ":" + _orchardServices.WorkContext.HttpContext.Request.Url.Port);

            var urlHelper = new UrlHelper(_orchardServices.WorkContext.HttpContext.Request.RequestContext);

            // Model template Mail
            dynamic viewModel = new UnsubscribeVM {
                Email = email,
                LinkUnsubscription = string.Format("{0}{1}?key={2}", host, urlHelper.ConfirmUnsubscribeMailCommunication(), parametriEncode),
                KeyUnsubscription  = Nonce,
                UnsubscriptionDate = DateTime.Now
            };

            var settings = _orchardServices.WorkContext.CurrentSite.As <MailCommunicationSettingsPart>();

            if (settings.IdTemplateUnsubscribe == null)
            {
                _orchardServices.Notifier.Error(T("Select in settings or create a template for e-mail unsubscribe"));
                return(false);
            }

            // Send Mail
            _templateServices.SendTemplatedEmail(viewModel, (int)settings.IdTemplateUnsubscribe, null, new List <string> {
                email
            }, null, false, null);

            return(true);
        }
コード例 #2
0
        public string CreatePaymentNonce(PaymentRecord paymentData)
        {
            var data = string.Format("reason={0}&amount={1}&currency={2}&itemId={3}",
                                     Uri.EscapeDataString(paymentData.Reason),
                                     Uri.EscapeDataString(Convert.ToString(paymentData.Amount, CultureInfo.InvariantCulture)),
                                     Uri.EscapeDataString(paymentData.Currency),
                                     Uri.EscapeDataString(Convert.ToString(paymentData.ContentItemId, CultureInfo.InvariantCulture)));
            var nonceDuration = _orchardServices.WorkContext.CurrentSite.As <PaymentGatewaySiteSettingsPart>().NonceMinutesDuration;

            return(Uri.EscapeDataString(_commonsServices.CreateNonce(data, TimeSpan.FromMinutes(nonceDuration))));
        }
コード例 #3
0
        public SubscriberRecord TryRegisterSubscriber(SubscriberViewModel subscriber)
        {
            SubscriberRecord returnValue = null;

            try {
                var subs = _repositorySubscribers.Table.Where(w => w.Email == subscriber.Email &&
                                                              w.NewsletterDefinition.Id == subscriber.NewsletterDefinition_Id).SingleOrDefault();

                string guid = Guid.NewGuid().ToString();

                // Create Nonce
                string   parametri = "Email=" + subscriber.Email + "&Guid=" + guid;
                TimeSpan delay     = new TimeSpan(1, 0, 0);
                string   Nonce     = _commonServices.CreateNonce(parametri, delay);

                if (subs == null)
                {
                    subs = new SubscriberRecord {
                        Email                = subscriber.Email,
                        Guid                 = guid,
                        Confirmed            = false,
                        SubscriptionDate     = DateTime.Now,
                        SubscriptionKey      = Nonce,
                        Name                 = subscriber.Name,
                        NewsletterDefinition = _repositoryNewsletterDefinition.Get(subscriber.NewsletterDefinition_Id)
                    };

                    try {
                        _repositorySubscribers.Create(subs);
                        returnValue = subs;
                    }
                    catch (Exception ex) {
                        _orchardServices.Notifier.Error(T(ex.Message));
                        returnValue = null;
                    }
                }
                else if (!subs.Confirmed)
                {
                    subs.Name               = subscriber.Name;
                    subs.SubscriptionDate   = DateTime.Now;
                    subs.SubscriptionKey    = Nonce;
                    subs.UnsubscriptionDate = null;

                    try {
                        _repositorySubscribers.Update(subs);
                        returnValue = subs;
                    }
                    catch (Exception ex) {
                        _orchardServices.Notifier.Error(T(ex.Message));
                        returnValue = null;
                    }
                }
                else
                {
                    _orchardServices.Notifier.Information(T("Email already registered!"));
                }
                if (returnValue != null)
                {
                    // Encode Nonce
                    string parametriEncode = System.Web.HttpUtility.HtmlEncode(Nonce.Replace('+', '_').Replace('/', '-'));

                    string host = string.Format("{0}://{1}{2}",
                                                _orchardServices.WorkContext.HttpContext.Request.Url.Scheme,
                                                _orchardServices.WorkContext.HttpContext.Request.Url.Host,
                                                _orchardServices.WorkContext.HttpContext.Request.Url.Port == 80 ? string.Empty : ":" + _orchardServices.WorkContext.HttpContext.Request.Url.Port);

                    var urlHelper = new UrlHelper(_orchardServices.WorkContext.HttpContext.Request.RequestContext);

                    // Model template Mail
                    dynamic viewModel = new SubscriberViewModel {
                        Email                   = subs.Email,
                        Name                    = subs.Name,
                        Guid                    = subs.Guid,
                        LinkSubscription        = string.Format("{0}{1}?key={2}", host, urlHelper.SubscriptionConfirmSubscribe(), parametriEncode),
                        KeySubscription         = Nonce,
                        NewsletterDefinition_Id = subs.NewsletterDefinition.Id,
                        NewsletterDefinition    = _contentManager.Get(subs.NewsletterDefinition.Id)
                    };

                    _templateService.SendTemplatedEmail(viewModel,
                                                        subs.NewsletterDefinition.ConfirmSubscrptionTemplateRecord_Id,
                                                        new List <string> {
                        subs.Email
                    }, null, null, false, null);
                }
            }
            catch {
                returnValue = null;
            }

            return(returnValue);
        }