コード例 #1
0
        private UserData ProcessLogin(string username, string password, bool passHashed, string ipAddr, string language, ref string errorMsg)
        {
            CultureInfo ci = new CultureInfo(language);

            UserData ud = UserMng.Login(username, password, passHashed, ipAddr);

            //string errorMsg = null;
            if (ud != null)
            {
                if (ud.SessionId == -1)
                {
                    errorMsg = Resources.Resources.ResourceManager.GetString("UI_MaxUserLoginCountReached", ci);
                    //errorMsg = Resources.Resources.UI_MaxUserLoginCountReached;
                }
                else if (ud.SessionId == -2)
                {
                    errorMsg = Resources.Resources.UI_SubscriptionExpired;
                }
                else if (ud.SessionId == -3)
                {
                    errorMsg = Resources.Resources.UI_EmailNotValidated;
                }
                else if (ud.SessionId == -4)
                {
                    errorMsg = Resources.Resources.ResourceManager.GetString("UI_UserNotActive", ci);
                    //errorMsg = Resources.Resources.UI_UserNotActive;
                }
                else if (ud.SessionId == -5)
                {
                    errorMsg = Resources.Resources.ResourceManager.GetString("UI_IpNotAllowed", ci);
                }
                else if (ud.SessionId > 0)
                {
                    Session["UserData"] = ud;
                    Session.Timeout     = ud.SessionTimeout; // minutes

                    var browserString   = Request.Browser.Browser;
                    var userAgentString = Request.UserAgent;
                    var browserId       = (int)GetBrowserByBrowserAndUserAgentString(browserString, userAgentString);
                    var isMobileDevice  = Request.Browser.IsMobileDevice;

                    if (Common.CheckRequestOriginIsBotSoft(userAgentString) == false)
                    {
                        Stat.AddLogin(ud.UserId, browserId, isMobileDevice, Request.UserHostAddress, ud.ClientId, ud.SellerId);
                    }

                    var productsList = UserMng.GetProductsList(ud.UserId);
                    Session["ProductsList"] = productsList;

                    var selectedProductCookie = Request.Cookies["SelectedProductId"];
                    int selectedProductId     = 1;

                    if (UserData.Products.Where(p => p.IsActive.HasValue && p.IsActive == true).ToList().Count == 1)
                    {
                        selectedProductId = UserData.Products.Where(p => p.IsActive.HasValue && p.IsActive == true).ToList().FirstOrDefault().ProductId;
                        var newCookie = new HttpCookie("SelectedProductId");
                        newCookie.Value = selectedProductId.ToString();

                        Response.SetCookie(newCookie);
                    }
                    else
                    {
                        if (selectedProductCookie != null && selectedProductCookie.Value != null && selectedProductCookie.Value.ToString() != "")
                        {
                            selectedProductId = int.Parse(selectedProductCookie.Value.ToString());
                        }
                    }

                    Session["SelectedProductId"] = selectedProductId;
                }
            }
            else
            {
                errorMsg = Resources.Resources.UI_InvalidLogin;
            }

            return(ud);
        }