Ejemplo n.º 1
0
        public static string GetLoginHistoryItem(RestCommand command, int loginHistoryID)
        {
            LoginHistoryItem loginHistoryItem = LoginHistory.GetLoginHistoryItem(command.LoginUser, loginHistoryID);

            if (loginHistoryItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(loginHistoryItem.GetXml("LoginHistoryItem", true));
        }
Ejemplo n.º 2
0
        public static void Authenticate(User user, bool isBackdoor, string deviceID)
        {
            if (IsAuthenticated(user, isBackdoor))
            {
                SlideExpiration();
            }
            else
            {
                Guid   guid     = Guid.NewGuid();
                string userData = GetUserDataString(user.UserID, user.OrganizationID, isBackdoor, guid.ToString(), user.IsSystemAdmin);
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.DisplayName, DateTime.UtcNow, DateTime.UtcNow.AddSeconds(TimeOut), false, userData, FormsAuthentication.FormsCookiePath);
                string     encTicket             = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                cookie.HttpOnly = true;
                cookie.Domain   = FormsAuthentication.CookieDomain;
                cookie.Expires  = DateTime.UtcNow.AddYears(1);
                HttpContext.Current.Response.Cookies.Add(cookie);

                if (!isBackdoor)
                {
                    user.LastLogin    = DateTime.UtcNow;
                    user.SessionID    = guid;
                    user.LastActivity = DateTime.UtcNow;
                    user.Collection.Save();
                }

                HttpBrowserCapabilities bc      = HttpContext.Current.Request.Browser;
                LoginHistoryItem        history = (new LoginHistory(LoginUser.Anonymous)).AddNewLoginHistoryItem();
                history.UserID         = user.UserID;
                history.Browser        = DataUtils.GetBrowserName(HttpContext.Current.Request.UserAgent);
                history.Version        = bc.Version;
                history.MajorVersion   = bc.MajorVersion.ToString();
                history.UserAgent      = HttpContext.Current.Request.UserAgent;
                history.Language       = "";
                history.Platform       = bc.Platform;
                history.CookiesEnabled = bc.Cookies;
                history.IPAddress      = HttpContext.Current.Request.UserHostAddress;
                history.PixelDepth     = bc.ScreenBitDepth.ToString();
                history.ScreenHeight   = bc.ScreenPixelsHeight.ToString();
                history.ScreenWidth    = bc.ScreenPixelsWidth.ToString();
                history.URL            = (isBackdoor ? "BACKDOOR - " : "") + HttpContext.Current.Request.Url.OriginalString;
                history.DeviceID       = deviceID;
                history.IsSupport      = isBackdoor;

                history.Collection.Save();
            }
        }