Esempio n. 1
0
        // GET: SMSNotification
        public ActionResult ValidatePhone(string referrer = null) //NOP 3.825
        {
            var model = new SMSNotificationRecordModel();

            TempData["Referrer"] = referrer;
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult ValidatePhone(SMSNotificationRecordModel model)
        {
            TempData.Keep();
            if (ModelState.IsValid)
            {
                //NOP 3.825
                var customerId     = _workContext.CurrentCustomer.Id;
                var activationCode = Guid.NewGuid().ToString().GetHashCode().ToString("x");
                var phoneNumber    = model.PhoneNumber;
                var active         = false;

                var currentPhoneNumber = _smsNotificationService.GetPhoneNumber(_workContext.CurrentCustomer.Id);

                if (currentPhoneNumber == null)
                {
                    var smsNotificationRecord = new SMSNotificationRecord();
                    smsNotificationRecord.CustomerId     = customerId;
                    smsNotificationRecord.ActivationCode = activationCode;
                    smsNotificationRecord.PhoneNumber    = phoneNumber;
                    smsNotificationRecord.Active         = active;
                    _smsNotificationService.InsertSMSRecord(smsNotificationRecord);
                }
                else
                {
                    var smsNotificationRecord = _smsNotificationService.GetByCustomerId(customerId);
                    smsNotificationRecord.CustomerId     = customerId;
                    smsNotificationRecord.ActivationCode = activationCode;
                    smsNotificationRecord.PhoneNumber    = phoneNumber;
                    smsNotificationRecord.Active         = active;
                    _smsNotificationService.UpdateSMSRecord(smsNotificationRecord);
                }


                if (_smsNotificationService.SendSMS(_smsNotificationSettings.RegisterMessage + " " + activationCode,
                                                    _smsNotificationSettings.PhoneNumber,
                                                    model.PhoneNumber, null, _smsNotificationSettings.UserName,
                                                    _smsNotificationSettings.Password, _smsNotificationSettings.BaseURL,
                                                    _smsNotificationSettings.Resource, _smsNotificationSettings.CountryCode))
                {
                    return(View("ValidatePhoneResult", model));
                }
                else
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Validatephone.Wrongnumber")); //NOP 3.829
                }
                //NOP 3.825
            }
            return(View("ValidatePhone", model));
        }