Exemplo n.º 1
0
    /// <summary>
    /// Removes user from site. Called when the "Remove user from site" button is pressed.
    /// Expects the AddUserToSite method to be run first.
    /// </summary>
    private bool RemoveUserFromSite()
    {
        // Get the user
        UserInfo removeUser = UserInfoProvider.GetUserInfo("MyNewUser");

        if (removeUser != null)
        {
            int siteId = CMSContext.CurrentSiteID;

            // Get the binding
            UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(removeUser.UserID, siteId);

            // Delete the binding
            UserSiteInfoProvider.DeleteUserSiteInfo(userSite);

            return(true);
        }

        return(false);
    }
    private void UserSite_Insert_After(object sender, ObjectEventArgs e)
    {
        UserSiteInfo UserSite = (UserSiteInfo)e.Object;
        UserInfo     User     = UserInfoProvider.GetUserInfo(UserSite.UserID);

        if (User.UserName.Equals("public", System.StringComparison.InvariantCultureIgnoreCase))
        {
            // Add to unauthenticated
            RoleInfo NotAuthenticatedUserRole = GetOrCreateRole(_NotAuthenticatedRole, _NotAuthenticatedRoleDisplayName, _NotAuthenticatedRoleDescription, UserSite.SiteID);
            HandleUserRole(UserSite.UserID, NotAuthenticatedUserRole.RoleID);
        }
        else
        {
            // Add to authenticated
            RoleInfo AuthenticatedUserRole = GetOrCreateRole(_AuthenticatedRole, _AuthenticatedRoleDisplayName, _AuthenticatedRoleDescription, UserSite.SiteID);
            HandleUserRole(UserSite.UserID, AuthenticatedUserRole.RoleID);
        }

        // Add to everyone
        RoleInfo EveryoneUserRole = GetOrCreateRole(_EveryoneRole, _EveryoneRoleDisplayName, _EveryoneRoleDescription, UserSite.SiteID);

        HandleUserRole(UserSite.UserID, EveryoneUserRole.RoleID);
    }
Exemplo n.º 3
0
        protected void PrepareData()
        {
            const int SITE1_ID = 1;

            SiteInfo currentSite;

            Fake <SiteInfo, SiteInfoProvider>().WithData(
                currentSite = SiteInfo.New(s =>
            {
                s.SiteID   = SITE1_ID;
                s.SiteName = "Site1";
            }),
                SiteInfo.New(s =>
            {
                s.SiteID   = 2;
                s.SiteName = "Site2";
            })
                );

            siteService = Substitute.For <ISiteService>();
            siteService.CurrentSite.Returns(currentSite);

            Fake <IssueInfo, IssueInfoProvider>().WithData(
                IssueInfo.New(issue =>
            {
                issue.IssueGUID        = Guid.Parse(GUID1);
                issue.IssueDisplayName = "Test1";
                issue.IssueSiteID      = SITE1_ID;
            }),
                IssueInfo.New(issue =>
            {
                issue.IssueGUID        = Guid.NewGuid();
                issue.IssueDisplayName = "Test2";
                issue.IssueSiteID      = 2;
            })
                );

            Fake <DataClassInfo, DataClassInfoProvider>().WithData(
                DataClassInfo.New(dc =>
            {
                dc.ClassDisplayName = "Test Class 1 Display Name";
                dc.ClassName        = "TestClass1";
            }),
                DataClassInfo.New(dc =>
            {
                dc.ClassDisplayName = "Test Class 2 Display Name";
                dc.ClassName        = "TestClass2";
                dc.ClassGUID        = Guid.Parse(GUID1);
            })
                );

            Fake <ContactGroupMemberInfo, ContactGroupMemberInfoProvider>();
            Fake <ContactInfo, ContactInfoProvider>().WithData(
                ContactInfo.New(contact =>
            {
                contact.ContactEmail    = "*****@*****.**";
                contact.ContactGUID     = Guid.Parse(GUID1);
                contact.ContactLastName = "TestLastName";
            })
                );

            Fake <UserSiteInfo, UserSiteInfoProvider>().WithData(
                UserSiteInfo.New(userSite =>
            {
                userSite.UserID = 1;
                userSite.SiteID = SITE1_ID;
            })
                );

            Fake <UserInfo, UserInfoProvider>().WithData(
                UserInfo.New(user =>
            {
                user.UserName = "******";
                user.UserID   = 1;
                user.UserGUID = Guid.Parse(GUID1);
            })
                );

            Fake <ActivityTypeInfo, ActivityTypeInfoProvider>().WithData(
                ActivityTypeInfo.New(at =>
            {
                at.ActivityTypeName = "Activity1";
            })
                );
        }
Exemplo n.º 4
0
    /// <summary>
    /// Saves data to DB without validation and permissions check.
    /// </summary>
    private void SaveData()
    {
        // If customer does not already exist, create new one
        if (Customer == null)
        {
            Customer = new CustomerInfo();
            Customer.CustomerSiteID  = currentSiteId;
            Customer.CustomerEnabled = true;
        }

        Customer.CustomerEmail             = txtCustomerEmail.Text.Trim().Truncate(100);
        Customer.CustomerFax               = txtCustomerFax.Text.Trim();
        Customer.CustomerLastName          = txtCustomerLastName.Text.Trim();
        Customer.CustomerPhone             = txtCustomerPhone.Text.Trim();
        Customer.CustomerFirstName         = txtCustomerFirstName.Text.Trim();
        Customer.CustomerCompany           = txtCustomerCompany.Text.Trim();
        Customer.CustomerCountryID         = drpCountry.CountryID;
        Customer.CustomerStateID           = drpCountry.StateID;
        Customer.CustomerOrganizationID    = txtOraganizationID.Text.Trim();
        Customer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim();

        // Set customer's preferences
        Customer.CustomerPreferredCurrencyID       = drpCurrency.CurrencyID;
        Customer.CustomerPreferredPaymentOptionID  = drpPayment.PaymentID;
        Customer.CustomerPreferredShippingOptionID = drpShipping.ShippingID;

        if (plcDiscounts.Visible && plcGlobalDiscount.Visible)
        {
            Customer.CustomerDiscountLevelID = drpGlobalDiscountLevel.DiscountLevel;
        }

        // Only registered customer can be enabled/disabled
        if (Customer.CustomerIsRegistered)
        {
            Customer.CustomerEnabled = chkCustomerEnabled.Checked;
        }

        using (CMSTransactionScope tr = new CMSTransactionScope())
        {
            bool newUserCreated = false;

            // Create user for customer
            if (chkHasLogin.Checked)
            {
                UserInfo ui = new UserInfo();
                ui.UserName = txtUserName.Text.Trim();
                ui.FullName = Customer.CustomerFirstName + " " + Customer.CustomerLastName;
                ui.IsGlobalAdministrator = false;
                ui.UserEnabled           = true;

                UserInfoProvider.SetPassword(ui, passStrength.Text);
                UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName);

                Customer.CustomerEnabled = true;
                Customer.CustomerUserID  = ui.UserID;

                chkCustomerEnabled.Checked = Customer.CustomerEnabled;

                newUserCreated = true;

                // Show fields requiring registered customer
                pnlEdit.Visible             = false;
                pnlStatic.Visible           = true;
                plcDiscounts.Visible        = true;
                plcPreferences.Visible      = true;
                chkHasLogin.Checked         = false;
                plcSiteDiscount.Visible     = true;
                lblUserNameStaticValue.Text = HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(ui.UserName));
                if (AllowEditUser)
                {
                    btnEditUser.OnClientClick = "modalDialog('" + CMSContext.ResolveDialogUrl("~/CMSModules/Membership/Pages/Users/User_Edit_Frameset.aspx") + "?userid=" + Customer.CustomerUserID + "', 'UserEdit', 950, 700); return false;";
                    btnEditUser.Visible       = true;
                }

                // Hide global discount level selector when global levels not allowed
                plcGlobalDiscount.Visible = allowGlobalDiscountLevels;
            }

            // Save customer
            CustomerInfoProvider.SetCustomerInfo(Customer);

            // Enable/disable corresponding registered user
            if (Customer.CustomerIsRegistered && !newUserCreated)
            {
                UserInfo ui = UserInfoProvider.GetUserInfo(Customer.CustomerUserID);

                // If the customer already has the record in the CMS_User table, update email
                if (ui != null)
                {
                    ui.Email = Customer.CustomerEmail;
                    UserInfoProvider.SetUserInfo(ui);
                }

                // Save site specific values
                UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(Customer.CustomerUserID, currentSiteId);
                if (userSite != null)
                {
                    userSite.UserPreferredCurrencyID       = drpCurrency.CurrencyID;
                    userSite.UserPreferredPaymentOptionID  = drpPayment.PaymentID;
                    userSite.UserPreferredShippingOptionID = drpShipping.ShippingID;
                    userSite.UserDiscountLevelID           = drpDiscountLevel.DiscountLevel;

                    UserSiteInfoProvider.SetUserSiteInfo(userSite);
                }
            }

            // Commit transaction
            tr.Commit();

            // Raise OnSaved event
            RaiseOnSaved();
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check module permissions
        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        string errorMessage = "";

        if ((txtCustomerCompany.Text.Trim() == "") &&
            ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == "")))
        {
            errorMessage = GetString("Customers_Edit.errorInsert");
        }
        else if (ECommerceSettings.RequireCompanyInfo(CMSContext.CurrentSite.SiteName) && (txtCustomerCompany.Text.Trim() != "" || txtOraganizationID.Text.Trim() != "" || txtTaxRegistrationID.Text.Trim() != ""))
        {
            errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text.Trim(), GetString("customers_edit.errorcompany"))
                           .NotEmpty(txtOraganizationID.Text.Trim(), GetString("customers_edit.errororganizationid"))
                           .NotEmpty(txtTaxRegistrationID.Text.Trim(), GetString("customers_edit.errortaxregid")).Result;
        }
        else if ((txtCustomerEmail.Text.Trim() != "") && !ValidationHelper.IsEmail(txtCustomerEmail.Text))
        {
            errorMessage = GetString("Customers_Edit.errorEmail");
        }

        if (chkHasLogin.Checked)
        {
            if (errorMessage == "")
            {
                errorMessage = new Validator().NotEmpty(txtUserName.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvUserName"))
                               .NotEmpty(passStrength.Text, GetString("Customer_Edit_Login_Edit.rqvPassword1"))
                               .NotEmpty(txtPassword2.Text, GetString("Customer_Edit_Login_Edit.rqvPassword2")).Result;
            }

            if ((errorMessage == "") && (passStrength.Text != txtPassword2.Text))
            {
                errorMessage = GetString("Customer_Edit_Login_Edit.DifferentPasswords");
            }

            // Check policy
            if ((errorMessage == "") && !passStrength.IsValid())
            {
                errorMessage = UserInfoProvider.GetPolicyViolationMessage(CMSContext.CurrentSiteName);
            }

            // Check if user name is unique
            if (errorMessage == "")
            {
                UserInfo existingUser = UserInfoProvider.GetUserInfo(txtUserName.Text.Trim());
                if (existingUser != null)
                {
                    errorMessage = GetString("Customer_Edit_Login_Edit.UserExist");
                }
            }
        }

        if (errorMessage == "")
        {
            CustomerInfo customerObj = CustomerInfoProvider.GetCustomerInfo(customerid);

            // If customer does not already exist, create new one
            if (customerObj == null)
            {
                customerObj = new CustomerInfo();
                customerObj.CustomerSiteID  = currentSiteId;
                customerObj.CustomerEnabled = true;
            }

            customerObj.CustomerEmail             = txtCustomerEmail.Text.Trim();
            customerObj.CustomerFax               = txtCustomerFax.Text.Trim();
            customerObj.CustomerLastName          = txtCustomerLastName.Text.Trim();
            customerObj.CustomerPhone             = txtCustomerPhone.Text.Trim();
            customerObj.CustomerFirstName         = txtCustomerFirstName.Text.Trim();
            customerObj.CustomerCompany           = txtCustomerCompany.Text.Trim();
            customerObj.CustomerCountryID         = drpCountry.CountryID;
            customerObj.CustomerStateID           = drpCountry.StateID;
            customerObj.CustomerOrganizationID    = txtOraganizationID.Text.Trim();
            customerObj.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim();

            // Set customer's preferences
            customerObj.CustomerPreferredCurrencyID       = drpCurrency.CurrencyID;
            customerObj.CustomerPreferredPaymentOptionID  = drpPayment.PaymentID;
            customerObj.CustomerPreferredShippingOptionID = drpShipping.ShippingID;

            if (plcDiscounts.Visible && plcGlobalDiscount.Visible)
            {
                customerObj.CustomerDiscountLevelID = drpGlobalDiscountLevel.DiscountLevel;
            }

            // Only registered customer can be enabled/diabled
            if (customerObj.CustomerIsRegistered)
            {
                customerObj.CustomerEnabled = chkCustomerEnabled.Checked;
            }

            bool refreshHeader = true;

            using (CMSTransactionScope tr = new CMSTransactionScope())
            {
                // Create user for customer
                if (chkHasLogin.Checked)
                {
                    UserInfo ui = new UserInfo();
                    ui.UserName = txtUserName.Text.Trim();
                    ui.FullName = customerObj.CustomerFirstName + " " + customerObj.CustomerLastName;
                    ui.IsGlobalAdministrator = false;
                    ui.UserEnabled           = true;

                    UserInfoProvider.SetPassword(ui, passStrength.Text);
                    UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName);

                    customerObj.CustomerEnabled = true;
                    customerObj.CustomerUserID  = ui.UserID;

                    refreshHeader = true;
                }

                // Save customer
                CustomerInfoProvider.SetCustomerInfo(customerObj);

                // Enable/disable coresponding registered user
                if (customerObj.CustomerIsRegistered && !chkHasLogin.Checked)
                {
                    UserInfo ui = UserInfoProvider.GetUserInfo(customerObj.CustomerUserID);

                    // If the customer already has the record in the CMS_User table, update email
                    if (ui != null)
                    {
                        ui.Email = customerObj.CustomerEmail;
                        UserInfoProvider.SetUserInfo(ui);
                    }

                    // Save site specific values
                    UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(customerObj.CustomerUserID, CMSContext.CurrentSiteID);
                    if (userSite != null)
                    {
                        userSite.UserPreferredCurrencyID       = drpCurrency.CurrencyID;
                        userSite.UserPreferredPaymentOptionID  = drpPayment.PaymentID;
                        userSite.UserPreferredShippingOptionID = drpShipping.ShippingID;
                        userSite.UserDiscountLevelID           = drpDiscountLevel.DiscountLevel;

                        UserSiteInfoProvider.SetUserSiteInfo(userSite);
                    }
                }

                // Commit transaction
                tr.Commit();
            }

            URLHelper.Redirect("Customer_Edit_General.aspx?customerid=" + Convert.ToString(customerObj.CustomerID) + "&saved=1&hidebreadcrumbs=" + QueryHelper.GetInteger("hidebreadcrumbs", 0) + "&siteId=" + SiteID + (refreshHeader ? "&refreshHeader=1" : ""));
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = "";
        string siteName     = CMSContext.CurrentSiteName;

        if ((txtCustomerCompany.Text.Trim() == "" || !chkCompanyAccount.Checked) &&
            ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == "")))
        {
            errorMessage = GetString("Customers_Edit.errorInsert");
        }
        // Check the following items if complete company info is required for company account
        if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && chkCompanyAccount.Checked)
        {
            errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany"))
                           .NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID"))
                           .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result;
        }

        if (errorMessage == "")
        {
            errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat")).Result;
        }

        plcCompanyInfo.Visible = chkCompanyAccount.Checked;

        if (errorMessage == "")
        {
            // If customer doesn't already exist, create new one
            if (mCustomer == null)
            {
                mCustomer = new CustomerInfo();
                mCustomer.CustomerEnabled = true;
                mCustomer.CustomerUserID  = CMSContext.CurrentUser.UserID;
            }

            int currencyId = selectCurrency.CurrencyID;

            if (ECommerceContext.CurrentShoppingCart != null)
            {
                ECommerceContext.CurrentShoppingCart.ShoppingCartCurrencyID = currencyId;
            }

            mCustomer.CustomerEmail     = txtCustomerEmail.Text.Trim();
            mCustomer.CustomerFax       = txtCustomerFax.Text.Trim();
            mCustomer.CustomerLastName  = txtCustomerLastName.Text.Trim();
            mCustomer.CustomerPhone     = txtCustomerPhone.Text.Trim();
            mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim();
            mCustomer.CustomerCountryID = drpCountry.CountryID;
            mCustomer.CustomerStateID   = drpCountry.StateID;
            mCustomer.CustomerCreated   = DateTime.Now;

            // Set customers's preferences
            mCustomer.CustomerPreferredCurrencyID       = (currencyId > 0) ? currencyId : 0;
            mCustomer.CustomerPreferredPaymentOptionID  = drpPayment.PaymentID;
            mCustomer.CustomerPreferredShippingOptionID = drpShipping.ShippingID;

            // Check if customer is registered
            if (mCustomer.CustomerIsRegistered)
            {
                // Find user-site binding
                UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(Customer.CustomerUserID, CMSContext.CurrentSiteID);
                if (userSite != null)
                {
                    // Set user's preferences
                    userSite.UserPreferredCurrencyID       = mCustomer.CustomerPreferredCurrencyID;
                    userSite.UserPreferredPaymentOptionID  = mCustomer.CustomerPreferredPaymentOptionID;
                    userSite.UserPreferredShippingOptionID = mCustomer.CustomerPreferredShippingOptionID;

                    UserSiteInfoProvider.SetUserSiteInfo(userSite);
                }
            }

            if (chkCompanyAccount.Checked)
            {
                mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim();
                if (ECommerceSettings.ShowOrganizationID(siteName))
                {
                    mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim();
                }
                if (ECommerceSettings.ShowTaxRegistrationID(siteName))
                {
                    mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim();
                }
            }
            else
            {
                mCustomer.CustomerCompany           = "";
                mCustomer.CustomerOrganizationID    = "";
                mCustomer.CustomerTaxRegistrationID = "";
            }

            // Update customer data
            CustomerInfoProvider.SetCustomerInfo(mCustomer);

            // Update corresponding user email
            UserInfo user = mCustomer.CustomerUser;
            if (user != null)
            {
                user.Email = mCustomer.CustomerEmail;
                UserInfoProvider.SetUserInfo(user);
            }

            // Update corresponding contact data
            ModuleCommands.OnlineMarketingUpdateContactFromExternalData(mCustomer, DataClassInfoProvider.GetDataClass(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled,
                                                                        ModuleCommands.OnlineMarketingGetCurrentContactID());

            // Let others now that customer was created
            if (OnCustomerCrated != null)
            {
                OnCustomerCrated();

                ShowChangesSaved();
            }
            else
            {
                URLHelper.Redirect(URLHelper.AddParameterToUrl(URLRewriter.CurrentURL, "saved", "1"));
            }
        }
        else
        {
            //Show error
            ShowError(errorMessage);
        }
    }