Exemplo n.º 1
0
    def _update_session(self, data: dict, sid: str):
        """Update existing session and add new information

        Args: 
            data: (dict) Infomation that should be stored in the database
            sid: (str) Session id where the data should be stored on
        """

        session = SessionModel.objects(sid=sid)
        if not session:
            return
        session = session[0]
        session.session_data = data
        session.save()
Exemplo n.º 2
0
    def _get_session(self, sid: str):
        """Try to open a session with the given id or create a new one

        Args:
            sid: Session id

        Return: object
            (dict) Data extracted from the session
            (str) Session id
        """

        model = SessionModel.objects(sid=sid)
        if not model:
            return {}
        model = dict(model[0].session_data)
        model.update({'_sid': sid})
        return model
Exemplo n.º 3
0
 def _destroy_session(self, sid: str) -> dict:
     """Delete session from the database"""
     SessionModel.objects(sid=sid).delete()