Exemple #1
0
    def prompt_for_login(self, req):

        # if ajax request, relative redirect won't work well
        # throw 401 error for now until we can figure out
        # better way to do it.

        # 401 error will be caught by jquery ajax error handler
        if req.is_AJAX:
            resp = Response.plain("You have to log in first!")

            resp.status = '401 UNAUTHORIZED'

        if req.is_JSON:
            resp = Response.json(dict(
                reply_timestamp=datetime.datetime.now(),
                message="You have to log in first!",
                success=False))

            resp.status = '401 UNAUTHORIZED'


        else:
            resp = Response.relative_redirect('/login',
                'You have to log in first!')

            # Redirect back to the page the person is hitting right now.
            resp.set_redirect_cookie(req.address_bar)

        return resp
Exemple #2
0
        def f(req):

            resp = Response.relative_redirect('/login', message)
            resp.set_redirect_cookie(redirect_location)
            return resp