Beispiel #1
0
 def logout(environ, start_response):
     session = environ[session_key].session
     if session is not None:
         if 'user' in session:
             del session['user']
     response = HTTPTemporaryRedirect(location='/')
     return response(environ, start_response)
Beispiel #2
0
 def _wrapper(context, REQUEST):
     """ admin required decorator """
     is_admin = users.is_current_user_admin()
     if is_admin:
         return func(context, REQUEST)
     else:
         return HTTPTemporaryRedirect(
             location=users.create_login_url(REQUEST.url))
Beispiel #3
0
    def __call__(self, environ, start_response):
        req = Request(environ)

        val = req.cookies.get(self.from_key)
        if val:
            log.info("Renaming %s=%s to %s on client IP %s", self.from_key,
                     val, self.to_key, req.remote_addr)
            resp = HTTPTemporaryRedirect(location=req.url)
            resp.delete_cookie(self.from_key)
            resp.set_cookie(self.to_key, val, **self.cookie_kwargs)
        else:
            resp = req.get_response(self.app)

        return resp(environ, start_response)
Beispiel #4
0
    def __call__(self, environ, start_response):
        req = Request(environ)

        to_delete = set()
        for cookie in req.cookies:
            if ((self.whitelist and (cookie not in self.whitelist))
                    or (self.blacklist and (cookie in self.blacklist))):
                to_delete.add(cookie)

        if to_delete:
            resp = HTTPTemporaryRedirect(location=req.url)
            for cookie in to_delete:
                resp.delete_cookie(cookie)
        else:
            resp = req.get_response(self.app)

        return resp(environ, start_response)
Beispiel #5
0
    def _intercept(self, context):
        """Called after dispatch has returned and the response populated, to intercept and redirect.
		
		Optionally assigned to the correct callback name (`after`) only if interception is enabled.
		"""

        if context.response.status_int not in self._intercept:
            return  # Exit early if our condition is not met.

        if not self._internal:
            context.response = HTTPTemporaryRedirect(location=self._handler)
            return  # External redirects are easy.

        # Internal redirection is a touch more difficult.

        request = context.request.copy_get(
        )  # Preserve the user's original request data, such as cookies.
        request.path = self._handler  # Point the internal request at the authentication endpoint.
        request.environ[
            'HTTP_REFERER'] = context.request.path_qs  # Inform authentication where the user was.

        response = request.send(context.app)  # Perform the internal redirect.
        response.status_int = context.response.status_int  # Match the status to ensure browser caching not applied.
        context.response = response  # Override the current (failed) response.
 def f(environ, start_response):
     return HTTPTemporaryRedirect(location=location)(environ, start_response)
Beispiel #7
0
def main(app, request):
    # return Response('this is man page')
    raise HTTPTemporaryRedirect(
        location='/r2/hello/jkzhao/26')  # 302临时跳转,webob内部实现了
Beispiel #8
0
def no_auth(request, token):
    """No authentication, just pass along"""
    callback = token.get_callback_url()
    return HTTPTemporaryRedirect(location=callback), None
def redirect(url, permanent=False):
    if permanent:
        return HTTPMovedPermanently(location=url)
    return HTTPTemporaryRedirect(location=url)
Beispiel #10
0
def main(application, request):
    #if application.options.get('debug'):
    #    for k, v in request.headers.items():
    #        print('{} => {}'.format(k, v))
    #return Response("this is a man page")
    raise HTTPTemporaryRedirect(location='/r2/hello/xxx/111')