コード例 #1
0
        public IEnumerable <ISession> GetSessions()
        {
            var sessions = _sessionManager.SearchAllEntities();

            return(SessionBuilder.NewSessionBuilder()
                   .SetAlarmClock(_alarmClock)
                   .SetConnectionString(_connectionString)
                   .BuildAll(sessions));
        }
コード例 #2
0
        public ISession GetSession(string sessionId)
        {
            var sessionEntity = _sessionManager.SearchEntity(sessionId);

            if (sessionEntity is null || !Session.DataValid(_alarmClock, sessionEntity))
            {
                return(null);
            }
            return(SessionBuilder.NewSessionBuilder()
                   .SetConnectionString(_connectionString)
                   .SetAlarmClock(_alarmClock)
                   .SetSessionEntity(sessionEntity)
                   .Build());
        }
コード例 #3
0
        public ISession Login(string username, string password)
        {
            Control.CheckPassword(password);

            var userEntity = _userManager.SearchEntity(username);

            if (userEntity is null || !Control.CompareHashPassword(Control.HashPassword(password), userEntity.Password))
            {
                return(null);
            }
            if (userEntity.Session is null)
            {
                var sessionEntity = EntitySessionBuilder.NewBuilder()
                                    .Id(username)
                                    .SiteName(Name)
                                    .ValidUntil(_alarmClock.Now.AddSeconds(SessionExpirationInSeconds))
                                    .Build();

                _sessionManager.SaveOnDb(sessionEntity);

                return(SessionBuilder.NewSessionBuilder()
                       .SetAlarmClock(_alarmClock)
                       .SetConnectionString(_connectionString)
                       .SetSessionEntity(sessionEntity)
                       .Build());
            }

            userEntity.Session.ValidUntil = _alarmClock.Now.AddSeconds(SessionExpirationInSeconds);

            _sessionManager.SaveOnDb(userEntity.Session, true);

            return(SessionBuilder.NewSessionBuilder()
                   .SetAlarmClock(_alarmClock)
                   .SetConnectionString(_connectionString)
                   .SetSessionEntity(userEntity.Session)
                   .Build());
        }