Exemplo n.º 1
0
        public static Domain.User GetLoggedInUser(System.Web.HttpSessionStateBase session, string userName)
        {
            if (session[USER] == null)
            {
                LoadDataIntoSession(session, userName);
            }

            return(session[USER] as Domain.User);
        }
Exemplo n.º 2
0
 public static void AddOnce(this System.Web.HttpSessionStateBase session, string key, dynamic value)
 {
     if (!String.IsNullOrEmpty(key))
     {
         if (session[key] == null)
         {
             session.Add(key, value);
         }
     }
 }
Exemplo n.º 3
0
 public static T GetValue <T>(this System.Web.HttpSessionStateBase sessionState, SessionKey sessionKey, T value)
 {
     if (sessionState[sessionKey.ToString()] != null)
     {
         return((T)sessionState[sessionKey.ToString()]);
     }
     else
     {
         return(value);
     }
 }
Exemplo n.º 4
0
        private static void LoadDataIntoSession(System.Web.HttpSessionStateBase session, string userName)
        {
            Repositories.UserRepository userRepo = new Repositories.UserRepository();

            Domain.User loggedUser = userRepo.GetUserDetails(userName);

            if (loggedUser != null)
            {
                loggedUser.Roles.AddRange(userRepo.GetRolesAsArray(loggedUser.Username));

                session[USER] = loggedUser;
            }
        }
Exemplo n.º 5
0
        public void CheckExceededMaxConcurrent(string username, System.Web.HttpSessionStateBase session)
        {
            if (!string.IsNullOrWhiteSpace(username))
            {
                _userDataAccess = new UserDataAccess(_context);

                if (session["sessionid"] == null)
                {
                    session["sessionid"] = "empty";
                }

                // check to see if your ID in the Logins table has LoggedIn = true - if so, continue, otherwise, redirect to Login page.
                if (_userDataAccess.IsYourLoginStillTrue(username, (session["sessionid"] as string)))
                {
                    // check to see if your user ID is being used elsewhere under a different session ID
                    if (!_userDataAccess.IsUserLoggedOnElsewhere(username, (session["sessionid"] as string)))
                    {
                        // Do nothing
                    }
                    else
                    {
                        // if it is being used elsewhere, update all their Logins records to LoggedIn = false, except for your session ID
                        _userDataAccess.LogEveryoneElseOut(username, (session["sessionid"] as string));
                    }
                }
                else
                {
                    // Go to Login page
                    session["sessionid"] = null;
                }
            }
            else
            {
                // Go to Logout page
                session["sessionid"] = null;
                session.Clear();
                session.Abandon();
                session.RemoveAll();
            }
        }
Exemplo n.º 6
0
 public static object GetValue(this System.Web.HttpSessionStateBase session, SessionIndex sindex)
 {
     return(session[sindex.ToString()]);
 }
Exemplo n.º 7
0
 public static void SetValue(this System.Web.HttpSessionStateBase session, SessionIndex sindex, object value)
 {
     session[sindex.ToString()] = value;
 }
Exemplo n.º 8
0
 public static void SetValue(this System.Web.HttpSessionStateBase sessionState, SessionKey sessionKey, object value)
 {
     sessionState[sessionKey.ToString()] = value;
 }
Exemplo n.º 9
0
 public static bool SessionKeyExists(this System.Web.HttpSessionStateBase sessionState, SessionKey sessionKey)
 {
     return(sessionState[sessionKey.ToString()] != null);
 }
Exemplo n.º 10
0
 public static void RemoveValue(this System.Web.HttpSessionStateBase sessionState, SessionKey sessionKey)
 {
     sessionState.Remove(sessionKey.ToString());
 }
Exemplo n.º 11
0
 public static T GetValue <T>(this System.Web.HttpSessionStateBase sessionState, SessionKey sessionKey)
 {
     return(GetValue <T>(sessionState, sessionKey, default(T)));
 }
Exemplo n.º 12
0
 public static void SetLoggedInUser(Domain.User user, System.Web.HttpSessionStateBase session)
 {
     session[USER] = user;
 }
Exemplo n.º 13
0
 public static void ReloadUser(System.Web.HttpSessionStateBase session, string userName)
 {
     LoadDataIntoSession(session, userName);
 }