Esempio n. 1
0
class SessionManager:
    def __init__(self, session):
        self._anchor = SessionAnchor(session)

    def setup(self):
        base_uuid = setup_session()
        assert base_uuid
        self._anchor.set_value(base_uuid)

    def reset(self):
        self._anchor.reset()
        self.setup()

    def refresh(self, json=True):
        base_uuid = self._anchor.refresh()
        if base_uuid: self.cleanup(base_uuid)
        self.setup()

        result = dict(success=True, timestamp=datetime.now())
        return jsonify(result) if json else result

    def cleanup(self, base_uuid):
        if not app.is_dev():
            base = Q(Node.query).one_or_default(uuid=base_uuid)
            if base:
                db.session.delete(base)
                db.session.commit()

    @property
    def authenticated(self):
        return current_user.is_authenticated() or app.is_dev()

    @property
    def virgin(self):
        return not self._anchor.initialized

    @property
    def anchor(self):
        return self._anchor.value
Esempio n. 2
0
class SessionManager:

    def __init__ (self, session):
        self._anchor = SessionAnchor (session)

    def setup (self):
        base_uuid = setup_session (); assert base_uuid
        self._anchor.set_value (base_uuid)

    def reset (self):
        self._anchor.reset ()
        self.setup ()

    def refresh (self, json=True):
        base_uuid = self._anchor.refresh ()
        if base_uuid: self.cleanup (base_uuid)
        self.setup ()

        result = dict (success=True, timestamp=datetime.now ())
        return jsonify (result) if json else result

    def cleanup (self, base_uuid):
        if not app.is_dev ():
            base = Q (Node.query).one_or_default (uuid=base_uuid)
            if base: db.session.delete (base); db.session.commit ()

    @property
    def authenticated (self):
        return current_user.is_authenticated () or app.is_dev ()

    @property
    def virgin (self):
        return not self._anchor.initialized

    @property
    def anchor (self):
        return self._anchor.value