Ejemplo n.º 1
0
 def _get_session(self):
     """
     Get the user's session from the datastore
     """
     query = UserSession.all()
     query.filter("sid", self.sid)
     if self.check_user_agent:
         query.filter("ua", os.environ["HTTP_USER_AGENT"])
     if self.check_ip:
         query.filter("ip", os.environ["REMOTE_ADDR"])
     results = query.fetch(1)
     if len(results) is 0:
         return None
     else:
         sessionAge = datetime.datetime.now() - results[0].last_activity
         if sessionAge.seconds > self.session_expire_time:
             results[0].delete()
             return None
         return results[0]
Ejemplo n.º 2
0
    def _clean_old_sessions(self):
        """
        Delete expired sessions from the datastore.

        This is only called for CLEAN_CHECK_PERCENT percent of requests because
        it could be rather intensive.
        """
        duration = datetime.timedelta(seconds=self.session_expire_time)
        session_age = datetime.datetime.now() - duration
        query = UserSession.all()
        query.filter("last_activity <", session_age)
        results = query.fetch(1000)
        for result in results:
            data_query = UserSessionData.all()
            query.filter("session", result)
            data_results = data_query.fetch(1000)
            for data_result in data_results:
                data_result.delete()
            memcache.delete("sid-" + str(result.key()))
            result.delete()
Ejemplo n.º 3
0
    def delete_all_sessions(self):
        """
        Deletes all sessions and session data from the data store and memcache.
        """
        all_sessions_deleted = False
        all_data_deleted = False

        while not all_sessions_deleted:
            query = UserSession.all()
            results = query.fetch(1000)
            if len(results) is 0:
                all_sessions_deleted = True
            else:
                for result in results:
                    result.delete()

        while not all_data_deleted:
            query = UserSessionData.all()
            results = query.fetch(1000)
            if len(results) is 0:
                all_data_deleted = True
            else:
                for result in results:
                    result.delete()