コード例 #1
0
        public UserSession VerifySession(string sessionId)
        {
            if (string.IsNullOrEmpty(sessionId))
            {
                return(null);
            }
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(null);
            }

            if (!userSession.UpdatedDate.HasValue)
            {
                return(null);
            }

            TimeSpan time = DateTime.Now - userSession.UpdatedDate.Value;

            if (time.Milliseconds > TIME_OUT_MINUTES * 60 * 1000)
            {
                userSessionRepository.Delete(sessionId);
            }
            else
            {
                userSessionRepository.Update(userSession);
                return(userSession);
            }
            return(null);
        }
コード例 #2
0
 public BaseResponse Logout(string sessionID)
 {
     try
     {
         IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
         userSessionRepository.Delete(sessionID);
         return(new BaseResponse
         {
             ErrorCode = (int)ErrorCode.None,
             Message = string.Empty
         });
     }
     catch (Exception ex)
     {
         return(new BaseResponse
         {
             ErrorCode = (int)ErrorCode.Error,
             Message = ex.Message
         });
     }
 }
        public async Task RefreshSessionAsync(Guid sessionId, Guid newSessionId,
                                              string sessionKey, string ipAddress, string userAgent)
        {
            var parentSession = await _userSessionRepository.GetByIdAsync(sessionId);

            if (parentSession.HasNoValue())
            {
                throw new ServiceException(Codes.SessionNotFound,
                                           $"Session with id '{sessionId}' has not been found.");
            }

            if (parentSession.Key != sessionKey)
            {
                throw new ServiceException(Codes.SessionKeyIsInvalid,
                                           $"Invalid session key: '{sessionKey}'");
            }

            var newSession = parentSession.Refresh(newSessionId,
                                                   _encrypter.GetRandomSecureKey(), sessionId, ipAddress, userAgent);

            await _userSessionRepository.AddAsync(newSession);

            _userSessionRepository.Delete(parentSession);
        }