Пример #1
0
        private bool Save()
        {
            var result = false;

            var account = HccApp.MembershipServices.Customers.Find(CustomerId);

            if (account == null)
            {
                account = new CustomerAccount();
            }

            var oldEmailAddress = account.Email.Trim().ToLower();
            var newEmailAddress = EmailField.Text.Trim().ToLower();
            var emailChanged    = oldEmailAddress != newEmailAddress;
            var isNewUser       = string.IsNullOrEmpty(CustomerId);

            account.Notes              = CommentField.Text.Trim();
            account.FirstName          = FirstNameField.Text.Trim();
            account.LastName           = LastNameField.Text.Trim();
            account.TaxExempt          = chkTaxExempt.Checked;
            account.TaxExemptionNumber = txtTaxExemptionNumber.Text.Trim();
            account.PricingGroupId     = PricingGroupDropDownList.SelectedValue;

            var usrStatus = CreateUserStatus.None;

            if (isNewUser) // Create NEW customer account
            {
                if (!MembershipUtils.CheckPasswordComplexity(Membership.Provider, PasswordField.Text.Trim()))
                {
                    ucMessageBox.ShowError(string.Format(Localization.GetString("revPassword.ErrorMessage"),
                                                         WebAppSettings.PasswordMinimumLength));
                    return(false);
                }

                account.Email    = EmailField.Text.Trim();
                account.Username = UsernameField.Text;
                result           = HccApp.MembershipServices.CreateCustomer(account, out usrStatus, PasswordField.Text.Trim());
            }
            else // Update EXIST customer account
            {
                result = HccApp.MembershipServices.UpdateCustomer(account, out usrStatus);

                // Send email changed notification
                if (result && emailChanged)
                {
                    if (HccApp.MembershipServices.UpdateCustomerEmail(account, newEmailAddress))
                    {
                        HccApp.CurrentRequestContext.IntegrationEvents.CustomerAccountEmailChanged(oldEmailAddress,
                                                                                                   account.Email);
                    }
                }
            }

            if (!result)
            {
                HandleCreationError(usrStatus);
            }

            return(result);
        }
Пример #2
0
        public ActionResult SetFirstPassword()
        {
            var email     = Request.Form["email"] ?? string.Empty;
            var password  = Request.Form["password"] ?? string.Empty;
            var orderbvin = Request.Form["orderbvin"] ?? string.Empty;

            var resp = new SimpleResponse {
                Success = true
            };

            var order = HccApp.OrderServices.Orders.FindForCurrentStore(orderbvin);

            if (order == null)
            {
                resp.Success   = false;
                resp.Messages += "Order id was invalid for password reset. ";
            }
            else
            {
                if (order.CustomProperties.Where(y => (y.DeveloperId == "hcc") &&
                                                 (y.Key == "allowpasswordreset") &&
                                                 (y.Value == "1")).Count() < 1)
                {
                    resp.Success   = false;
                    resp.Messages +=
                        "This order does not allow password reset anymore. Please use the 'Forgot Password' link when signing in. ";
                }
            }

            if (!MembershipUtils.CheckPasswordComplexity(Membership.Provider, password.Trim()))
            {
                resp.Success   = false;
                resp.Messages += "Password must be at least " + WebAppSettings.PasswordMinimumLength +
                                 " characters long. ";
            }

            if (resp.Success)
            {
                try
                {
                    var userId = Convert.ToInt32(order.UserID);
                    DnnUserController.Instance.ResetPassword(userId, password, "");

                    // Turn off reset key so that this can only happen once.
                    var prop = order.CustomProperties.FirstOrDefault(y => (y.DeveloperId == "hcc") &&
                                                                     (y.Key == "allowpasswordreset") &&
                                                                     (y.Value == "1"));
                    if (prop != null)
                    {
                        prop.Value = "0";
                    }
                    HccApp.OrderServices.Orders.Update(order);
                }
                catch (Exception ex)
                {
                    resp.Success  = false;
                    resp.Messages = ex.Message;
                }
            }

            return(new PreJsonResult(Web.Json.ObjectToJson(resp)));
        }