Example #1
0
        protected void BillingAddress_AddressUpdate(object sender, AddressEventArgs e)
        {
            // update the user instance, user instance might be changed if a new account is registered
            _user   = AbleContext.Current.User;
            _basket = _user.Basket;

            if (e.Address.IsValid)
            {
                // if anonymous user or guest checkout then validate email address, check if it is not already registerd
                string email = e.Address.Email;
                if (_user.IsAnonymousOrGuest && UserDataSource.IsEmailRegistered(email))
                {
                    EmailRegisteredPanel.Visible = true;
                }
                else
                {
                    // Update user primary address
                    Address address = _user.PrimaryAddress;
                    if (address.Id != e.Address.Id)
                    {
                        address.FirstName  = e.Address.FirstName;
                        address.LastName   = e.Address.LastName;
                        address.Nickname   = e.Address.Nickname;
                        address.FullName   = e.Address.FullName;
                        address.Address1   = e.Address.Address1;
                        address.Address2   = e.Address.Address2;
                        address.City       = e.Address.City;
                        address.Company    = e.Address.Company;
                        address.Country    = e.Address.Country;
                        address.Email      = e.Address.Email;
                        address.Fax        = e.Address.Fax;
                        address.IsBilling  = e.Address.IsBilling;
                        address.Phone      = e.Address.Phone;
                        address.PostalCode = e.Address.PostalCode;
                        address.Province   = e.Address.Province;
                    }
                    address.Save();

                    BillingAddressTextPanel.Visible = true;
                    FormattedBillingAddress.Text    = GetFormattedAddressString(e.Address);
                    BillingAddress.Visible          = false;

                    _basketService.Package(_basket, true);
                    BasketShipment shipment = _basket.Shipments.FirstOrDefault();
                    if (shipment != null)
                    {
                        if (shipment.Address == null || shipment.Address.Id == address.Id)
                        {
                            BindShippingMethods(address, true);
                        }
                    }
                    IntializeEmailLists();
                }
            }
        }
Example #2
0
        private bool CreateAccount()
        {
            // NEED TO REGISTER USER
            if (AbleContext.Current.User.IsAnonymous)
            {
                // VALIDATE EMAIL, IF EMAIL IS ALREADY REGISTERED, ASK FOR LOGIN
                string newEmail = StringHelper.StripHtml(Email.Text);
                if (UserDataSource.IsEmailRegistered(newEmail))
                {
                    IList <string> warningMessages = new List <string>();
                    warningMessages.Add("The email address you have provided is already registered.Please sign in to access your account.");
                    WarningMessageList.DataSource = warningMessages;
                    WarningMessageList.DataBind();
                    return(false);
                }

                // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT
                User   oldUser     = AbleContext.Current.User;
                string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                string newPassword = Guid.NewGuid().ToString("N");
                MembershipCreateStatus createStatus;
                User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus);

                // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                if (createStatus == MembershipCreateStatus.Success)
                {
                    // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                    newUser.UserName                   = "******" + newUser.Id.ToString() + "@domain.xyz";
                    newUser.PrimaryAddress.Email       = newEmail;
                    newUser.PrimaryAddress.CountryCode = AbleContext.Current.Store.DefaultWarehouse.CountryCode;
                    newUser.PrimaryAddress.IsBilling   = true;
                    newUser.PrimaryAddress.Residence   = true;
                    newUser.Save();
                    CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true);
                    AbleContext.Current.User = newUser;
                    FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                }
            }

            return(true);
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string provinceName = string.Empty;

            if (!ValidateProvince(out provinceName))
            {
                return;
            }

            // NEED TO REGISTER USER
            if (AbleContext.Current.User.IsAnonymousOrGuest)
            {
                if (CreateAccountPh.Visible)
                {
                    bool result = false;
                    result = ValidatePassword();
                    if (result)
                    {
                        // PERFORM CUSTOM VALIDATION TO ENSURE EMAIL IS NOT ALREADY REGISTERED
                        string userName = StringHelper.StripHtml(Email.Text);
                        if (!UserDataSource.IsEmailRegistered(userName))
                        {
                            // CHECK IF THE USER GUEST ACCOUNT EXISTS ALREADY
                            if (AbleContext.Current.User.IsGuest)
                            {
                                // MIGRATE ACTIVE USER TO NEW ACCOUNT
                                AbleContext.Current.User.UserName = userName;
                                AbleContext.Current.User.SetPassword(Password.Text);
                                AbleContext.Current.User.Save();
                                FormsAuthentication.SetAuthCookie(userName, false);
                            }
                            else
                            {
                                // NO USER REGISTERED WITH THAT USERNAME OR EMAIL
                                MembershipCreateStatus status;
                                User newUser = UserDataSource.CreateUser(userName, userName, Password.Text, string.Empty, string.Empty, true, 0, out status);
                                if (status == MembershipCreateStatus.Success)
                                {
                                    // WE HAVE TO VALIDATE CREDENTIALS SO A MODIFIED FORM POST CANNOT ACCESS THIS CODE
                                    if (Membership.ValidateUser(userName, Password.Text))
                                    {
                                        // MIGRATE ACTIVE USER TO NEW ACCOUNT
                                        CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, newUser, true, true, true);
                                        AbleContext.Current.User = newUser;
                                        FormsAuthentication.SetAuthCookie(userName, false);
                                    }
                                }
                                else
                                {
                                    result = false;
                                    InvalidRegistration.IsValid = result;
                                    switch (status)
                                    {
                                    case MembershipCreateStatus.DuplicateUserName:
                                    case MembershipCreateStatus.DuplicateEmail:
                                        InvalidRegistration.ErrorMessage = "The user-name you have provided is already registered.  Sign in to access your account.";
                                        break;

                                    case MembershipCreateStatus.InvalidEmail:
                                        InvalidRegistration.ErrorMessage = "The email address you have provided is not valid.";
                                        break;

                                    case MembershipCreateStatus.InvalidUserName:
                                        InvalidRegistration.ErrorMessage = "The user-name you have provided is not valid.";
                                        break;

                                    case MembershipCreateStatus.InvalidPassword:
                                        InvalidRegistration.ErrorMessage = "The password you have provided is not valid.";
                                        break;

                                    default:
                                        InvalidRegistration.ErrorMessage = "Unexpected error in registration (" + status.ToString() + ")";
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            result = false;
                            DuplicateEmailValidator.IsValid = false;
                        }
                    }

                    if (!result)
                    {
                        return;
                    }
                }
                else if (AbleContext.Current.User.IsAnonymous)
                {
                    // VALIDATE EMAIL, IF EMAIL IS ALREADY REGISTERED, ASK FOR LOGIN
                    string newEmail = StringHelper.StripHtml(Email.Text);
                    if (UserDataSource.IsEmailRegistered(newEmail))
                    {
                        InvalidRegistration.IsValid      = false;
                        InvalidRegistration.ErrorMessage = "The email address you have provided is already registered. Please sign in to access your account.";
                        return;
                    }

                    // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT
                    User   oldUser     = AbleContext.Current.User;
                    string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                    string newPassword = Guid.NewGuid().ToString("N");
                    MembershipCreateStatus createStatus;
                    User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus);

                    // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                        newUser.UserName = "******" + newUser.Id.ToString() + "@domain.xyz";
                        newUser.Save();
                        CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true);
                        AbleContext.Current.User = newUser;
                        FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                    }
                }
            }

            string address1  = StringHelper.StripHtml(Address1.Text);
            string address2  = StringHelper.StripHtml(Address2.Text);
            string city      = StringHelper.StripHtml(City.Text);
            string postColde = StringHelper.StripHtml(PostalCode.Text);

            if (_address.Address1 != address1 || _address.Address2 != address2 || _address.City != city || _address.Province != provinceName || _address.PostalCode != postColde)
            {
                _address.Validated = false;
            }
            _address.FirstName = StringHelper.StripHtml(FirstName.Text);
            _address.LastName  = StringHelper.StripHtml(LastName.Text);
            if (CollectEmail)
            {
                _address.Email = StringHelper.StripHtml(Email.Text);
            }
            _address.Address1    = address1;
            _address.Address2    = address2;
            _address.Company     = StringHelper.StripHtml(Company.Text);
            _address.City        = city;
            _address.Province    = provinceName;
            _address.PostalCode  = postColde;
            _address.CountryCode = Country.SelectedValue;
            _address.Phone       = StringHelper.StripHtml(Telephone.Text);
            _address.Fax         = StringHelper.StripHtml(Fax.Text);
            _address.Residence   = Residence.SelectedIndex == 0;

            if (OnAddressUpdate != null)
            {
                OnAddressUpdate(this, new AddressEventArgs(_address));
            }
        }
        protected void BillingPageContinue_Click(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string nextPageUrl = "Payment.aspx";

                // NEED TO REGISTER USER
                if (AbleContext.Current.User.IsAnonymous)
                {
                    if (CreateNewAccountPanel.Visible)
                    {
                        if (!CreateNewAccount())
                        {
                            return;
                        }
                    }
                    else
                    {
                        // VALIDATE EMAIL, IF EMAIL IS ALREADY REGISTERED, ASK FOR LOGIN
                        string newEmail = StringHelper.StripHtml(BillToEmail.Text);
                        if (UserDataSource.IsEmailRegistered(newEmail))
                        {
                            InvalidRegistration.IsValid      = false;
                            InvalidRegistration.ErrorMessage = "The email address you have provided is already registered. Please sign in to access your account.";
                            return;
                        }

                        // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT
                        User   oldUser     = AbleContext.Current.User;
                        string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                        string newPassword = Guid.NewGuid().ToString("N");
                        MembershipCreateStatus createStatus;
                        User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus);

                        // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                        if (createStatus == MembershipCreateStatus.Success)
                        {
                            // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                            newUser.UserName = "******" + newUser.Id.ToString() + "@domain.xyz";
                            newUser.Save();
                            CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true);
                            AbleContext.Current.User = newUser;
                            FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                        }
                    }
                }

                // MAILING LIST SIGNUP
                if (EmailLists.Visible && EmailLists.Items.Count > 0)
                {
                    string            email      = AbleContext.Current.User.Email;
                    int               listIndex  = 0;
                    IList <EmailList> emailLists = GetPublicEmailLists();
                    if (emailLists != null && emailLists.Count > 0)
                    {
                        foreach (ListViewDataItem item in EmailLists.Items)
                        {
                            EmailList list     = emailLists[listIndex];
                            CheckBox  selected = (CheckBox)item.FindControl("Selected");
                            if (selected != null)
                            {
                                if (selected.Checked)
                                {
                                    list.ProcessSignupRequest(email);
                                }
                                else
                                {
                                    list.RemoveMember(email);
                                }
                            }
                            else
                            {
                                list.RemoveMember(email);
                            }
                            listIndex++;
                        }
                    }
                }

                string provinceName;
                if (ValidateProvince(out provinceName))
                {
                    Address address = AbleContext.Current.User.PrimaryAddress;
                    address.FirstName   = StringHelper.StripHtml(FirstName.Text);
                    address.LastName    = StringHelper.StripHtml(LastName.Text);
                    address.Address1    = StringHelper.StripHtml(Address1.Text);
                    address.Address2    = StringHelper.StripHtml(Address2.Text);
                    address.Company     = StringHelper.StripHtml(Company.Text);
                    address.Email       = CreateNewAccountPanel.Visible ? StringHelper.StripHtml(UserName.Text) : StringHelper.StripHtml(BillToEmail.Text);
                    address.City        = StringHelper.StripHtml(City.Text);
                    address.Province    = provinceName;
                    address.PostalCode  = StringHelper.StripHtml(PostalCode.Text);
                    address.CountryCode = Country.SelectedValue;
                    address.Phone       = StringHelper.StripHtml(Telephone.Text);
                    address.Fax         = StringHelper.StripHtml(Fax.Text);
                    address.Residence   = !IsBusinessAddress.Checked;
                    address.Save();
                }
                else
                {
                    Province2Invalid.IsValid = false;
                    UpdateCountry();
                }

                if (ShippingAddressPanel.Visible)
                {
                    nextPageUrl = "ShipAddress.aspx";
                }

                Response.Redirect(nextPageUrl);
            }
        }
        protected bool CreateNewAccount()
        {
            bool result = false;

            if (Page.IsValid && ValidatePassword())
            {
                if ((!trCaptchaField.Visible) || CaptchaImage.Authenticate(CaptchaInput.Text))
                {
                    // PERFORM CUSTOM VALIDATION TO ENSURE EMAIL IS NOT ALREADY REGISTERED
                    string userName = StringHelper.StripHtml(UserName.Text.Trim());
                    if (!UserDataSource.IsEmailRegistered(userName))
                    {
                        // NO USER REGISTERED WITH THAT USERNAME OR EMAIL
                        MembershipCreateStatus status;
                        User newUser = UserDataSource.CreateUser(userName, userName, Password.Text, string.Empty, string.Empty, true, 0, out status);
                        if (status == MembershipCreateStatus.Success)
                        {
                            // WE HAVE TO VALIDATE CREDENTIALS SO A MODIFIED FORM POST CANNOT ACCESS THIS CODE
                            if (Membership.ValidateUser(userName, Password.Text))
                            {
                                // SET A DEFAULT BILLING ADDRESS FOR THE USER
                                newUser.PrimaryAddress.Email       = userName;
                                newUser.PrimaryAddress.CountryCode = AbleContext.Current.Store.DefaultWarehouse.CountryCode;
                                newUser.PrimaryAddress.Residence   = true;
                                newUser.Save();

                                // MIGRATE ACTIVE USER TO NEW ACCOUNT
                                CommerceBuilder.Users.User.Migrate(AbleContext.Current.User, newUser, false, true);
                                AbleContext.Current.User = newUser;
                                FormsAuthentication.SetAuthCookie(userName, false);
                                result = true;
                            }
                        }
                        else
                        {
                            InvalidRegistration.IsValid = false;
                            switch (status)
                            {
                            case MembershipCreateStatus.DuplicateUserName:
                            case MembershipCreateStatus.DuplicateEmail:
                                InvalidRegistration.ErrorMessage = "The user-name you have provided is already registered.  Sign in to access your account.";
                                break;

                            case MembershipCreateStatus.InvalidEmail:
                                InvalidRegistration.ErrorMessage = "The email address you have provided is not valid.";
                                break;

                            case MembershipCreateStatus.InvalidUserName:
                                InvalidRegistration.ErrorMessage = "The user-name you have provided is not valid.";
                                break;

                            case MembershipCreateStatus.InvalidPassword:
                                InvalidRegistration.ErrorMessage = "The password you have provided is not valid.";
                                break;

                            default:
                                InvalidRegistration.ErrorMessage = "Unexpected error in registration (" + status.ToString() + ")";
                                break;
                            }
                        }
                    }
                    else
                    {
                        DuplicateEmailValidator.IsValid = false;
                    }
                }
                else
                {
                    //CAPTCHA IS VISIBLE AND DID NOT AUTHENTICATE
                    CustomValidator invalidInput = new CustomValidator();
                    invalidInput.ID           = Guid.NewGuid().ToString();
                    invalidInput.Text         = "*";
                    invalidInput.ErrorMessage = "You did not input the verification number correctly.";
                    invalidInput.IsValid      = false;
                    phCaptchaValidators.Controls.Add(invalidInput);
                    CaptchaInput.Text = "";
                    Password.Attributes.Add("value", string.Empty);
                    RefreshCaptcha();
                }
            }

            return(result);
        }
Example #6
0
        private bool UpdateAddress(bool validate)
        {
            // NEED TO REGISTER USER
            if (AbleContext.Current.User.IsAnonymous)
            {
                if (CreateNewAccountPanel.Visible)
                {
                    if (!CreateNewAccount())
                    {
                        return(false);
                    }
                    else
                    {
                        CreateNewAccountPanel.Visible = false;
                    }
                }
                else
                {
                    // VALIDATE EMAIL, IF EMAIL IS ALREADY REGISTERED, ASK FOR LOGIN
                    string newEmail = StringHelper.StripHtml(BillToEmail.Text);
                    if (UserDataSource.IsEmailRegistered(newEmail))
                    {
                        InvalidRegistration.IsValid      = false;
                        InvalidRegistration.ErrorMessage = "The email address you have provided is already registered. Please sign in to access your account.";
                        return(false);
                    }

                    // ANONYMOUS USER SELECTING GUEST CHECKOUT, CREATE TEMPORARY ACCOUNT
                    User   oldUser     = AbleContext.Current.User;
                    string newUserName = "******" + Guid.NewGuid().ToString("N") + "@domain.xyz";
                    string newPassword = Guid.NewGuid().ToString("N");
                    MembershipCreateStatus createStatus;
                    User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, 0, out createStatus);

                    // IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        // CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
                        newUser.UserName = "******" + newUser.Id.ToString() + "@domain.xyz";
                        newUser.Save();
                        CommerceBuilder.Users.User.Migrate(oldUser, newUser, true, true);
                        AbleContext.Current.User = newUser;
                        FormsAuthentication.SetAuthCookie(newUser.UserName, false);
                    }
                }
            }

            // MAILING LIST SIGNUP
            if (EmailLists.Visible && EmailLists.Items.Count > 0)
            {
                string            email      = AbleContext.Current.User.Email;
                int               listIndex  = 0;
                IList <EmailList> emailLists = GetPublicEmailLists();
                if (emailLists != null && emailLists.Count > 0)
                {
                    foreach (ListViewDataItem item in EmailLists.Items)
                    {
                        EmailList list     = emailLists[listIndex];
                        CheckBox  selected = (CheckBox)item.FindControl("Selected");
                        if (selected != null)
                        {
                            if (selected.Checked)
                            {
                                EmailListSignup signup = EmailListSignupDataSource.Load(list.Id, email);
                                if (signup == null || signup.SignupDate < LocaleHelper.LocalNow.AddMinutes(-5))
                                {
                                    list.ProcessSignupRequest(email);
                                }
                            }
                            else
                            {
                                list.RemoveMember(email);
                            }
                        }
                        else
                        {
                            list.RemoveMember(email);
                        }
                        listIndex++;
                    }
                }
            }

            string provinceName = string.Empty;

            if (ValidateProvince(out provinceName))
            {
                Address address   = AbleContext.Current.User.PrimaryAddress;
                string  address1  = StringHelper.StripHtml(Address1.Text);
                string  address2  = StringHelper.StripHtml(Address2.Text);
                string  city      = StringHelper.StripHtml(City.Text);
                string  postColde = StringHelper.StripHtml(PostalCode.Text);
                if (address.Address1 != address1 || address.Address2 != address2 || address.City != city || address.Province != provinceName || address.PostalCode != postColde)
                {
                    address.Validated = false;
                }
                address.FirstName   = StringHelper.StripHtml(FirstName.Text);
                address.LastName    = StringHelper.StripHtml(LastName.Text);
                address.Address1    = address1;
                address.Address2    = address2;
                address.Company     = StringHelper.StripHtml(Company.Text);
                address.Email       = trEmail.Visible ? StringHelper.StripHtml(BillToEmail.Text) : StringHelper.StripHtml(UserName.Text);
                address.City        = city;
                address.Province    = provinceName;
                address.PostalCode  = postColde;
                address.CountryCode = Country.SelectedValue;
                address.Phone       = StringHelper.StripHtml(Telephone.Text);
                address.Fax         = StringHelper.StripHtml(Fax.Text);
                address.Residence   = !IsBusinessAddress.Checked;
                address.Save();

                if (validate && !address.Validated && _addressValidator != null)
                {
                    AddressValidationResponse avr = _addressValidator.ValidateAddress(address);
                    if (avr != null)
                    {
                        if (!avr.IsValid.HasValue || !avr.IsValid.Value)
                        {
                            ValidAddresses = avr.Addresses;
                            if (ValidAddresses != null)
                            {
                                int index = 0;
                                foreach (ValidAddress validAddress in ValidAddresses)
                                {
                                    validAddress.Id = ++index;
                                }

                                ValidAddressesList.DataSource = ValidAddresses;
                                ValidAddressesList.DataBind();
                                ValidAddressesPanel.Visible = true;
                                ValidAddressesList.Items.Add(new ListItem("Use the address exactly as I entered it", "0"));
                                ValidAddressesList.Items[0].Selected = true;
                                if (ValidAddressesList.Items.Count > 1)
                                {
                                    PHAddressFound.Visible = true;
                                    PHNoAddress.Visible    = false;
                                }
                                else
                                {
                                    PHAddressFound.Visible = false;
                                    PHNoAddress.Visible    = true;
                                }

                                return(false);
                            }
                        }
                    }
                }
            }
            else
            {
                Province2Invalid.IsValid = false;
                UpdateCountry();
                return(false);
            }

            return(true);
        }