protected void Page_Load(object sender, System.EventArgs e)
        {
            if (AppLogic.AppConfigBool("GoNonSecureAgain"))
            {
                SkinBase.GoNonSecureAgain();
            }

            _itemCounter   = "ProductID".ToQueryString().TryParseIntUsLocalization().Value;
            CategoryID     = "CategoryID".ToQueryString();
            DepartmentID   = "DepartmentID".ToQueryString();
            ManufacturerID = "ManufacturerID".ToQueryString();

            _itemCode = AppLogic.GetItemCodeByCounter(_itemCounter);

            var eCommerceProductInfoView = AppLogic.GetProductInfoViewForShowProduct(DB.SQuote(_itemCode),
                                                                                     DB.SQuote(ThisCustomer.LocaleSetting),
                                                                                     DB.SQuote(InterpriseHelper.ConfigInstance.UserCode),
                                                                                     DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode),
                                                                                     DB.SQuote(Localization.DateTimeStringForDB(DateTime.Now)),
                                                                                     DB.SQuote(ThisCustomer.ProductFilterID),
                                                                                     DB.SQuote(ThisCustomer.ContactCode));

            int sessionLifetime = AppLogic.AppConfigUSInt("ViewedProductsSessionLifetime");

            if (sessionLifetime == null)
            {
                sessionLifetime = 60;
            }

            if (ThisCustomer.ContactCode == "")
            {
                RequireCustomerRecord();
            }

            //DateTime expirationdatetime = DateTime.Now.AddMinutes(-sessionLifetime);
            //string updatevieweditems =
            //        string.Format("exec UpdateEcommerceViewedItems @ExpirationDate = {0}, @WebSiteCode = {1}, @ContactCode = {2}, @ItemCode = {3}, @CurrentDate = {4}, @SessionID = {5}",
            //        DB.SQuote(Localization.DateTimeStringForDB(expirationdatetime)),
            //        DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode),
            //        DB.SQuote(ThisCustomer.ContactCode),
            //        DB.SQuote(_itemCode),
            //        DB.SQuote(Localization.DateTimeStringForDB(DateTime.Now)),
            //        ThisCustomer.CurrentSessionID);
            //DB.ExecuteSQL(updatevieweditems);

            string itemDescription = string.Empty;

            if (eCommerceProductInfoView == null)
            {
                Response.Redirect(SE.MakeDriverLink("ProductNotFound"));
            }

            if (eCommerceProductInfoView.CheckOutOption)
            {
                Response.Redirect(SE.MakeDriverLink("ProductNotFound"));
            }

            if (eCommerceProductInfoView.IsCBN == false && AppLogic.IsCBNMode())
            {
                Response.Redirect(SE.MakeDriverLink("MobileProductNotFound"));
            }

            string SENameINURL  = "SEName".ToQueryStringDecode();
            string ActualSEName = eCommerceProductInfoView.ItemDescription.ToMungeName().ToUrlEncode().ToSubString(90);

            if (string.IsNullOrEmpty(ActualSEName))
            {
                ActualSEName = eCommerceProductInfoView.ItemName.ToMungeName().ToUrlEncode().ToSubString(90);
            }

            if (ActualSEName != SENameINURL)
            {
                string NewURL    = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(_itemCounter.ToString(), ActualSEName);
                string QStr      = "?";
                var    keyvalues = Request.QueryString
                                   .ToPairs()
                                   .Where(q => q.Key == "productid" && q.Key == "sename")
                                   .Select(q => string.Join("=", new[] { q.Key, q.Value + "&" }))
                                   .ToArray();
                QStr += string.Join("", keyvalues);
                if (QStr.Length > 1)
                {
                    NewURL += QStr;
                }

                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }

            m_XmlPackage = eCommerceProductInfoView.MobileXmlPackage.ToLowerInvariant();

            IsAKit   = eCommerceProductInfoView.IsAKit.TryParseBool();
            IsMatrix = eCommerceProductInfoView.IsMatrix.TryParseBool();

            if (m_XmlPackage.Length == 0)
            {
                if (IsAKit)
                {
                    m_XmlPackage = AppLogic.MobileDefaultProductKitXmlPackage; // provide a default
                }
                else if (IsMatrix)
                {
                    m_XmlPackage = AppLogic.MobileDefaultProductMatrixXmlPackage; // provide a default
                }
                else
                {
                    m_XmlPackage = AppLogic.MobileDefaultProductXmlPackage; // provide a default
                }
            }

            RequiresReg = eCommerceProductInfoView.RequiresRegistration;
            ProductName = XmlCommon.GetLocaleEntry(eCommerceProductInfoView.ItemDescription, ThisCustomer.LocaleSetting, true);

            CategoryHelper     = AppLogic.LookupHelper(base.EntityHelpers, DomainConstants.LOOKUP_HELPER_CATEGORIES);
            SectionHelper      = AppLogic.LookupHelper(base.EntityHelpers, DomainConstants.LOOKUP_HELPER_DEPARTMENT);
            ManufacturerHelper = AppLogic.LookupHelper(base.EntityHelpers, DomainConstants.LOOKUP_HELPER_MANUFACTURERS);

            itemDescription = eCommerceProductInfoView.ItemDescription;
            if (string.IsNullOrEmpty(itemDescription))
            {
                itemDescription = ProductName;
            }

            string seITitleTemp = XmlCommon.GetLocaleEntry(eCommerceProductInfoView.SETitle, ThisCustomer.LocaleSetting, true);

            SETitle = string.IsNullOrEmpty(seITitleTemp) ? (AppLogic.AppConfig("StoreName") + " - " + itemDescription).ToHtmlEncode() : seITitleTemp;

            string seDescription = XmlCommon.GetLocaleEntry(eCommerceProductInfoView.SEDescription, ThisCustomer.LocaleSetting, true);

            SEDescription = string.IsNullOrEmpty(seDescription) ? ProductName.ToHtmlEncode() : seDescription;

            string seKeywords = XmlCommon.GetLocaleEntry(eCommerceProductInfoView.SEKeywords, ThisCustomer.LocaleSetting, true);

            SEKeywords = string.IsNullOrEmpty(seKeywords) ? ProductName.ToHtmlEncode() : seKeywords;

            SENoScript = XmlCommon.GetLocaleEntry(eCommerceProductInfoView.SENoScript, ThisCustomer.LocaleSetting, true);

            CategoryName = (CategoryHelper.GetEntityField(CategoryID, "Description", ThisCustomer.LocaleSetting) != String.Empty) ?
                           CategoryHelper.GetEntityField(CategoryID, "Description", ThisCustomer.LocaleSetting) :
                           CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting);

            SectionName = (SectionHelper.GetEntityField(DepartmentID, "Description", ThisCustomer.LocaleSetting) != String.Empty) ?
                          SectionHelper.GetEntityField(DepartmentID, "Description", ThisCustomer.LocaleSetting) :
                          SectionHelper.GetEntityName(DepartmentID, ThisCustomer.LocaleSetting);

            ManufacturerName = (ManufacturerHelper.GetEntityField(ManufacturerID, "Description", ThisCustomer.LocaleSetting) != String.Empty) ?
                               ManufacturerHelper.GetEntityField(ManufacturerID, "Description", ThisCustomer.LocaleSetting) :
                               ManufacturerHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting);

            if (ManufacturerID.Length != 0)
            {
                CookieTool.Add("LastViewedEntityName", "Manufacturer", new TimeSpan(1, 0, 0, 0, 0));
                CookieTool.Add("LastViewedEntityInstanceID", ManufacturerID.ToString(), new TimeSpan(1, 0, 0, 0, 0));
                CookieTool.Add("LastViewedEntityInstanceName", ManufacturerName, new TimeSpan(1, 0, 0, 0, 0));
                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(_itemCounter.ToString(), _itemCode);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (CategoryID.Length != 0)
            {
                CookieTool.Add("LastViewedEntityName", "Category", new TimeSpan(1, 0, 0, 0, 0));
                CookieTool.Add("LastViewedEntityInstanceID", CategoryID.ToString(), new TimeSpan(1, 0, 0, 0, 0));
                CookieTool.Add("LastViewedEntityInstanceName", CategoryName, new TimeSpan(1, 0, 0, 0, 0));
                string NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(_itemCounter.ToString(), _itemCode);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }
            else if (DepartmentID.Length != 0)
            {
                var cookierExpires = new TimeSpan(1, 0, 0, 0, 0);
                CookieTool.Add("LastViewedEntityName", "Department", cookierExpires);
                CookieTool.Add("LastViewedEntityInstanceID", DepartmentID.ToString(), cookierExpires);
                CookieTool.Add("LastViewedEntityInstanceName", SectionName, cookierExpires);

                String NewURL = AppLogic.GetStoreHTTPLocation(false) + SE.MakeProductLink(_itemCounter.ToString(), _itemCode);
                HttpContext.Current.Response.Write("<html><head><title>Object Moved</title></head><body><b>Object moved to <a href=\"" + NewURL + "\">HERE</a></b></body></html>");
                Response.Status = "301 Moved Permanently";
                Response.AddHeader("Location", NewURL);
                HttpContext.Current.Response.End();
            }

            SourceEntity = CommonLogic.CookieCanBeDangerousContent("LastViewedEntityName", true);
            string SourceEntityInstanceName = CommonLogic.CookieCanBeDangerousContent("LastViewedEntityInstanceName", true);

            SourceEntityID = CommonLogic.CookieCanBeDangerousContent("LastViewedEntityInstanceID", true);

            // validate that source entity id is actually valid for this product:
            if (SourceEntityID.Length != 0)
            {
                var alE = AppLogic.GetProductEntityList(_itemCode, SourceEntity);
                if (alE.Any(i => i == SourceEntityID.TryParseIntUsLocalization()))
                {
                    SourceEntityID = string.Empty;
                }
            }

            if (SourceEntityID.Length != 0)
            {
                PickupBreadCrumb(ref SourceEntity, ref SourceEntityInstanceName, ref SourceEntityID, false);
            }
            else
            {
                PickupBreadCrumb(ref SourceEntity, ref SourceEntityInstanceName, ref SourceEntityID, true);
            }

            AppLogic.LogEvent(ThisCustomer.CustomerCode, 10, _itemCounter.ToString());
        }
Beispiel #2
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string EMailField    = EMail.Text.ToLower();
            string PasswordField = Password.Text;

            if (AppLogic.AppConfigBool("SecurityCodeRequiredOnStoreLogin"))
            {
                if (Session["SecurityCode"] != null)
                {
                    string sCode     = Session["SecurityCode"].ToString();
                    string fCode     = SecurityCode.Text;
                    bool   codeMatch = false;

                    if (AppLogic.AppConfigBool("Captcha.CaseSensitive"))
                    {
                        if (fCode.Equals(sCode))
                        {
                            codeMatch = true;
                        }
                    }
                    else
                    {
                        if (fCode.Equals(sCode, StringComparison.InvariantCultureIgnoreCase))
                        {
                            codeMatch = true;
                        }
                    }

                    if (!codeMatch)
                    {
                        ErrorMsgLabel.Text     = string.Format(AppLogic.GetString("signin.aspx.22", SkinID, ThisCustomer.LocaleSetting), string.Empty, string.Empty);
                        ErrorPanel.Visible     = true;
                        SecurityCode.Text      = string.Empty;
                        SecurityImage.ImageUrl = "Captcha.ashx?id=1";
                        return;
                    }
                }
                else
                {
                    ErrorMsgLabel.Text     = string.Format(AppLogic.GetString("signin.aspx.22", SkinID, ThisCustomer.LocaleSetting), string.Empty, string.Empty);
                    ErrorPanel.Visible     = true;
                    SecurityCode.Text      = String.Empty;
                    SecurityImage.ImageUrl = "Captcha.ashx?id=1";
                    return;
                }
            }

            if (string.IsNullOrEmpty(EMailField) ||
                string.IsNullOrEmpty(EMailField.Trim()) ||
                string.IsNullOrEmpty(PasswordField) ||
                string.IsNullOrEmpty(PasswordField.Trim()))
            {
                DisplayInvalidLogin();
                return;
            }

            if (!CheckValidEmail())
            {
                return;
            }

            var customerWithValidLogin = Customer.FindByLogin(EMail.Text, PasswordField);

            if (customerWithValidLogin == null)
            {
                DisplayInvalidLogin();
                return;
            }

            bool isAllowed = InterpriseHelper.ValidateContactSubscription(customerWithValidLogin);

            if (!isAllowed)
            {
                DisplayInvalidLogin();
                return;
            }

            //check if remember me
            if (PersistLogin.Checked)
            {
                CookieTool.Add(REMEMBERME_COOKIE_NAME, customerWithValidLogin.ContactGUID.ToString(), DateTime.Now.AddDays(30));
            }
            else
            {
                CookieTool.Add(REMEMBERME_COOKIE_NAME, string.Empty, DateTime.Now.AddYears(-10));
            }

            //save the last record of fullmode to the loggedin user to maintain the view mode
            customerWithValidLogin.FullModeInMobile = ThisCustomer.FullModeInMobile;

            // dis-associate the session information if any..
            ThisCustomer.ThisCustomerSession.Clear();

            // we've got a good login...
            AppLogic.ExecuteSigninLogic(ThisCustomer.CustomerCode, ThisCustomer.ContactCode, customerWithValidLogin.CustomerCode, string.Empty, customerWithValidLogin.ContactCode);

            // we've got a good login:
            FormPanel.Visible    = false;
            ExecutePanel.Visible = true;

            ThisCustomer.ThisCustomerSession["ContactID"] = customerWithValidLogin.ContactGUID.ToString();
            SignInExecuteLabel.Text = AppLogic.GetString("signin.aspx.2", SkinID, ThisCustomer.LocaleSetting);

            InterpriseHelper.CreateContactSiteLog(customerWithValidLogin, "Login");

            string cookieUserName         = customerWithValidLogin.ContactGUID.ToString();
            bool   createPersistentCookie = PersistLogin.Checked;

            //To handle multiple domain ie bug
            if (Request.Browser.Browser == "IE" &&
                Request.Cookies.Keys.OfType <string>()
                .Where(k => k.ToUpper() == FormsAuthentication.FormsCookieName)
                .Count() > 1)
            {
                var autCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (autCookie != null)
                {
                    string encryptedData = FormsAuthentication.Encrypt(
                        new FormsAuthenticationTicket(1, cookieUserName, DateTime.Now, DateTime.Now.AddMinutes(30),
                                                      createPersistentCookie, string.Empty, FormsAuthentication.FormsCookiePath));
                    autCookie.Value = encryptedData;
                    Request.Cookies.Set(autCookie);
                    Response.Cookies.Set(autCookie);
                }
            }
            else
            {
                FormsAuthentication.SetAuthCookie(cookieUserName, createPersistentCookie);
            }

            string sReturnURL = DoingCheckout.Checked ? "shoppingcart.aspx" : "default.aspx";

            if (sReturnURL.Contains("default.aspx"))
            {
                sReturnURL = "account.aspx";
            }

            Response.AddHeader("REFRESH", "1; URL=" + sReturnURL.ToUrlDecode());
        }