Beispiel #1
0
def clear(req, **params):
    """ Obliterate the session. """

    sess = Session(req)
    if not sess.is_new():
        sess.invalidate()

    req.content_type = 'application/json'
    return json.dumps(dict(success=True), ensure_ascii=False)
Beispiel #2
0
def clear(req, **params):
    """ Obliterate the session. """

    sess = Session(req)
    if not sess.is_new():
        sess.invalidate()

    req.content_type = 'application/json'
    return json.dumps(dict(success=True), ensure_ascii=False)
Beispiel #3
0
class session(object):

    session = None

    def __init__(self, core):
        self.request = core.request
        self.core = core

        try:
            self.cookie_name = core.config.apache_options['mod_python.session.cookie_name']
        except:
            self.cookie_name = 'pysid'

        try:
            self.pysid = self.core.input.cookie(self.cookie_name)
        except:
            self.pysid = None

        self.core.log_message(1, '------------ Session Handler Initialised')

    def __init_session(self, pysid):

        self.session = Session(req=self.request, sid=pysid, lock=self.core.config.settings['session']['lock'])

        if self.session.is_new():
            self.session.set_timeout(self.core.config.settings['session']['timeout'])
            self.session.save()

    def start(self):

        try:
            self.__init_session(self.pysid)
        except ValueError:
            self.__init_session(None)

    def get_id(self):

        if self.session == None:
            self.start()

        return self.session.id()

    def set(self, name, value):

        if self.session == None:
            self.start()

        self.session[name] = value
        self.session.save()

    def get(self, name = None):

        if not self.session:
            self.start()

        try:
            if not name:
                return self.session

            return self.session[name]
        except:
            return None

    def destroy(self):
        self.session.invalidate()
        self.session.delete()