public static void Logout(string sessionID) { var sesh = UserSessions.Where(X => X.sessionID == sessionID).FirstOrDefault(); UserSessions.Remove(sesh); //isLoggedIn = false; //LoginToken = null; }
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}"); } }
public static bool isLoggedIn(string sessionID) { var currentSesh = UserSessions.Where(x => x.sessionID == sessionID); if (currentSesh.Any()) { return(true); } else { return(false); } }
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"); } }
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"); } }
/// <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); }
public bool SessionFull() { return(UserSessions.Where(p => p.SessionId == SessionId).Count() >= Capacity); }
public ICollection <User> GetUsers() { List <User> result = UserSessions.Where(u => u.SessionId == SessionId).Select(u => u.User).ToList(); return(result); }
public bool IsRegistered(int sessionId) { return(UserSessions.Where(us => us.UserId == Id && us.SessionId == sessionId).Any()); }