Exemplo n.º 1
0
Arquivo: cms.py Projeto: quantmind/lux
    def page_response(self, request, page, context=None,
                      jscontext=None, title=None, status_code=None):
        """Html response for a page.

        :param request: the :class:`.WsgiRequest`
        :param page: A :class:`Page`, template file name or a list of
            template filenames
        :param context: optional context dictionary
        """
        request.response.content_type = 'text/html'
        doc = request.html_document
        if jscontext:
            doc.jscontext.update(jscontext)

        if title:
            doc.head.title = title

        if status_code:
            request.response.status_code = status_code
        context = self.context(request, context)
        body = self.render_body(request, page, context)

        doc.body.append(body)

        if not request.config['MINIFIED_MEDIA']:
            doc.head.embedded_js.insert(
                0, 'window.minifiedMedia = false;')

        if doc.jscontext:
            encoded = encode_json(doc.jscontext, self.config['SECRET_KEY'])
            doc.head.add_meta(name="html-context", content=encoded)

        return doc.http_response(request)
Exemplo n.º 2
0
    def encode_token(self, request, user=None, expiry=None, **token):
        """Encode a JWT
        """
        if expiry:
            token['exp'] = int(time.mktime(expiry.timetuple()))

        request.app.fire('on_token', request, token, user)
        return jwt.encode_json(token, request.config['SECRET_KEY'])
Exemplo n.º 3
0
def app_token(request):
    app = request.app
    payload = {
        'app_name': app.config['APP_NAME'],
        'url': request.absolute_uri('/')[:-1]
    }
    app.fire('on_jwt', request, payload)
    return encode_json(
        payload,
        app.config['SECRET_KEY'],
        algorithm=app.config['JWT_ALGORITHM']
    )
Exemplo n.º 4
0
def app_token(request):
    app = request.app
    payload = {
        'app_name': app.config['APP_NAME'],
        'url': request.absolute_uri('/')[:-1]
    }
    app.fire('on_jwt', request, payload)
    return encode_json(
        payload,
        app.config['SECRET_KEY'],
        algorithm=app.config['JWT_ALGORITHM']
    )
Exemplo n.º 5
0
def app_token(request):
    app = request.app
    payload = {"app_name": app.config["APP_NAME"], "url": request.absolute_uri("/")[:-1]}
    app.fire("on_jwt", request, payload)
    return encode_json(payload, app.config["SECRET_KEY"], algorithm=app.config["JWT_ALGORITHM"])
Exemplo n.º 6
0
 def jwt(self, request, instance):
     data = self.tojson(request, instance)
     secret = data.pop('secret')
     return encode_json(data, secret,
                        algorithm=request.config['JWT_ALGORITHM'])
Exemplo n.º 7
0
 def jwt(self, request, instance):
     data = self.tojson(request, instance)
     secret = data.pop('secret')
     return encode_json(data,
                        secret,
                        algorithm=request.config['JWT_ALGORITHM'])