public void GhostLogin()
        {
            Guid ghostSessionId = Guid.Empty;
            Guid ghostBasketId  = Guid.Empty;

            if (Request.QueryString["sid"] != null)
            {
                Guid.TryParse(Sanitizer.GetSafeHtmlFragment(Request.QueryString["sid"]), out ghostSessionId);
            }
            var httpContext = DependencyResolver.Current.GetService <HttpContextBase>();

            httpContext.Session[Constants.SESSION_USERID] = Guid.Empty;
            var sessionContext = DependencyResolver.Current.GetService <ISessionContext>();

            sessionContext.CurrentUser = new CustomerModel {
                UserId = Guid.Empty
            };
            sessionContext.CreateUserSession(true);
            httpContext.Session[Constants.SESSION_CACHED_USER] = null;
            var cookie_deviceId = new HttpCookie(Constants.COOKIE_DEVICEID)
            {
                HttpOnly = true, Value = Convert.ToString(Guid.NewGuid()), Expires = DateTime.Now.AddDays(Constants.COOKIE_DEVICEID_EXPIRES_DAYS)
            };

            httpContext.Response.Cookies.Add(cookie_deviceId);
            httpContext.Session.Abandon();

            if (ghostSessionId != Guid.Empty)
            {
                var ghostLogin = _customerRepository.AuthenticateGhostLogin(Convert.ToString(ghostSessionId));
                if (ghostLogin != null && ghostLogin.Result != null)
                {
                    ghostLogin.Result.AdminUserName = ghostLogin.Message;
                    ghostLogin.Result.SessionId     = ghostSessionId.ToString();
                    _authenticationService.GhostLogin(ghostLogin.Result);
                }
                SiteUtils.SetBasketAction(resetAction: true);
                Response.Redirect("~/");
            }
        }
Exemplo n.º 2
0
        public void GhostLogin()
        {
            Guid ghostSessionId = Guid.Empty;
            Guid ghostBasketId  = Guid.Empty;

            if (Request.QueryString["sid"] != null)
            {
                Guid.TryParse(Sanitizer.GetSafeHtmlFragment(Request.QueryString["sid"]), out ghostSessionId);
            }
            if (ghostSessionId != Guid.Empty)
            {
                var ghostLogin = _customerRepository.AuthenticateGhostLogin(Convert.ToString(ghostSessionId));
                if (ghostLogin != null && ghostLogin.Result != null)
                {
                    ghostLogin.Result.AdminUserName = ghostLogin.Message;
                    ghostLogin.Result.SessionId     = ghostSessionId.ToString();
                    _authenticationService.GhostLogin(ghostLogin.Result);
                }
                SiteUtils.SetBasketAction(resetAction: true);
                Response.Redirect("~/");
            }
        }