Example #1
0
        private UserSession FetchOrCreateSession(
            IUserSessionStore sessionService, string dbName, string login, IDictionary <string, object> userFields)
        {
            Debug.Assert(sessionService != null);
            Debug.Assert(userFields.ContainsKey("password"));

            var uid = (long)userFields[IdFieldName];

            var oldSession = sessionService.GetByUserId(uid);

            if (oldSession == null)
            {
                var newSession = new UserSession(login, uid);
                sessionService.Put(newSession);
                return(newSession);
            }
            else if (!oldSession.IsActive)
            {
                sessionService.Remove(oldSession.Token);
                var newSession = new UserSession(login, uid);
                sessionService.Put(newSession);
                return(newSession);
            }
            else
            {
                sessionService.Pulse(oldSession.Token);
                return(oldSession);
            }
        }