示例#1
0
        public static void Logout(string sessionID)
        {
            var sesh = UserSessions.Where(X => X.sessionID == sessionID).FirstOrDefault();

            UserSessions.Remove(sesh);
            //isLoggedIn = false;
            //LoginToken = null;
        }
示例#2
0
        public void RemoveUserSession(User user)
        {
            UserSession us = UserSessions.Where(u => u.Session == this && u.User == user).FirstOrDefault();

            if (us != null)
            {
                UserSessions.Remove(us);
            }
            else
            {
                throw new Exception($"User not found for session: {this}");
            }
        }
示例#3
0
        public static bool isLoggedIn(string sessionID)
        {
            var currentSesh = UserSessions.Where(x => x.sessionID == sessionID);

            if (currentSesh.Any())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        public static string retrieveToken(string sessionID)
        {
            var currentSesh = UserSessions.Where(x => x.sessionID == sessionID).FirstOrDefault();

            if (currentSesh != null && !(currentSesh.expiryTimestamp < DateTime.Now))
            {
                return(currentSesh.authToken);
            }
            else
            {
                UserSessions.Remove(currentSesh);
                return("expired");
            }
        }
示例#5
0
 public void AddUserSession(User user)
 {
     if (!SessionFull() && user.UserStatus != UserStatus.BLOCKED && !UserSessions.Where(us => us.User == user).Any())
     {
         UserSession us = new UserSession();
         us.User      = user;
         us.UserId    = user.UserId;
         us.SessionId = SessionId;
         us.Session   = this;
         UserSessions.Add(us);
     }
     else
     {
         throw new Exception("Er moeten beschikbare plekken zijn en je mag geen blocked user zijn");
     }
 }
示例#6
0
        /// <summary>
        /// Gets an UserSession or creates new if not exists
        /// </summary>
        /// <param name="userID">User ID</param>
        /// <returns></returns>
        public UserSession ObtainUserSession(long userID)
        {
            UserSession userSession = null;

            // Try to get the User's respective UserSession from UserConcurrentList, create new if not exists.
            userSession = UserSessions?
                          .Where(uS => uS.UserID == userID)
                          .FirstOrDefault();
            if (userSession == null)
            {
                // Create new UserSession for the User and add to UserSessions
                UserSessions.Add(userSession = new UserSession(userID));
            }

            return(userSession);
        }
示例#7
0
 public bool SessionFull()
 {
     return(UserSessions.Where(p => p.SessionId == SessionId).Count() >= Capacity);
 }
示例#8
0
        public ICollection <User> GetUsers()
        {
            List <User> result = UserSessions.Where(u => u.SessionId == SessionId).Select(u => u.User).ToList();

            return(result);
        }
示例#9
0
 public bool IsRegistered(int sessionId)
 {
     return(UserSessions.Where(us => us.UserId == Id && us.SessionId == sessionId).Any());
 }