Ejemplo n.º 1
0
    def logout(self):
        request = self.request

        redis = pedis.db()

        redis.delete('session:' + str(request.account.sessionID))
        self.request.clear_cookie('session')
        request.account = None
Ejemplo n.º 2
0
    def loadByUser(self, user):
        redis = pedis.db()
        request = self.request
        session = self.genSessionID(user.uid)

        json = {
            'uid': user.uid,
            'name': user.username,
            'email': user.email,
            'role': user.role
        }

        session_id = str(session)

        redis.setex('session:' + session_id, json_encode(json), 24 * 60 * 60)
        redis.delete('session:' + str(request.account.sessionID))
        request.set_secure_cookie('session', session_id)

        request.account = Account(json['uid'],  session.session_id, json['role'], json['name'], json['email'], request.remote_ip)
Ejemplo n.º 3
0
    def loadByRequest(self):
        redis = pedis.db()
        request = self.request
        session = SessionID.fromSession(request.get_secure_cookie('session'))

        json = None
        if session is not None:
            data = redis.get('session:' + str(session))
            if data:
                try:
                    json = json_decode(data)
                except:
                    pass

        if json is None:

            json = self.any_user
            session = self.genSessionID(json['uid'])
            session_id = str(session)
            redis.setex('session:' + session_id, json_encode(json), 30 * 60)
            request.set_secure_cookie('session', session_id)

        request.account = Account(json['uid'],  session.session_id, json['role'], json['name'], json['email'], request.remote_ip)