Example #1
0
    def get_session(cls,cookies):
        """
        returns the session if it's not expired or nonexistant
        """
        cookie = SimpleCookie(cookies)
        session_id = cookie['session_id'].value
        
        db = cls._core.get_db()
        stmnt = "SELECT SES_USR_ID, SES_EXPIRES FROM SESSIONS WHERE SES_ID = ? ;"

        cur = db.query(cls._core,stmnt,(session_id,))
        row = cur.fetchonemap()

        session=None

        if row is not None:
            user_manager = cls._core.get_user_manager()
            user = user_manager.get_user_by_id(row["SES_USR_ID"])
            session = Session(cls._core,user)
            session._id = session_id
            expiration = row["SES_EXPIRES"]
            if expiration < datetime.now():
                raise SessionException(SessionException.get_msg(0))    
            session._expiration = row["SES_EXPIRES"]
        else:
            raise SessionException(SessionException.get_msg(2))
        return session
Example #2
0
    def get_session(cls,cookies):
        """
        returns the session if it's not expired or nonexistant
        """
        cookie = SimpleCookie(cookies)
        session_id = cookie['session_id'].value
        
        db = Database()
        stmnt = "SELECT SES_USR_ID, SES_EXPIRES FROM SESSIONS WHERE SES_ID = ? ;"

        cur = db.query(stmnt,(session_id,))
        row = cur.fetchonemap()

        session=None

        if row is not None:
            user = User.get_user_by_id(row["SES_USR_ID"])
            session = Session(user)
            session._id = session_id
            expiration = row["SES_EXPIRES"]
            if expiration < datetime.now():
                raise SessionException(SessionException.get_msg(0))    
            session._expiration = row["SES_EXPIRES"]
        else:
            raise SessionException(SessionException.get_msg(2))
        return session
Example #3
0
 def set_user(self,user):
     """
     set the user of this session
     """
     if type(user) == int:
         self._user = user
     elif user.__class__.__name__ == "User":
         self._user = user.get_id()
     else:
         raise SessionException(SessionException.get_msg(1))
Example #4
0
    def store(self):
        """
        stores this session in database
        """
        if self._user is None:
            raise SessionException(SessionException.get_msg(3))
        else:
            db = self._core.get_db()
            stmnt = "UPDATE OR INSERT INTO SESSIONS (SES_ID, SES_USR_ID, SES_EXPIRES) VALUES (?,?,?) MATCHING (SES_ID) ;"
            
            exp = datetime2fdbTimestamp(self._expiration)

            db.query(self._core,stmnt,(self._id,self._user,exp),commit=True)
Example #5
0
 def set_user(self,user):
     """
     set the user of this session
     """
     if type(user) == int:
         self._user = user
     elif user.__class__.__name__ == "User":
         self._user = user.get_id()
     else:
         raise SessionException(SessionException.get_msg(1))
Example #6
0
    def store(self):
        """
        stores this session in database
        """
        if self._user is None:
            raise SessionException(SessionException.get_msg(3))
        else:
            db = Database()
            stmnt = "UPDATE OR INSERT INTO SESSIONS (SES_ID, SES_USR_ID, SES_EXPIRES) VALUES (?,?,?) MATCHING (SES_ID) ;"
            
            exp = datetime2fdbTimestamp(self._expiration)

            db.query(stmnt,(self._id,self._user,exp),commit=True)