public string BeginSession(int userId) { var sessions = repository.GetAll<Session>(); if (!settings.AllowMultipleLogins) { foreach (var session in sessions.Where(session => !session.Outdated && session.User.Id == userId)) { session.Outdated = true; } } var user = repository.GetById<User>(userId); //user.IsOnline = true; var newSession = new Session { User = user, Outdated = false, SessionGuid = Guid.NewGuid(), StartedAt = DateTime.Now }; repository.Add(newSession); repository.Submit(); return newSession.SessionGuid.ToString(); }
private bool ValidateSession(int userId, Session session) { if (session == null) { return false; } if (userId != session.User.Id || session.StartedAt + settings.DefaultSessionLiveTime < DateTime.Now || session.Outdated) { return false; } return true; }