Skip to content

Instantly share code, notes, and snippets.

@jayd3e
Last active August 29, 2015 14:07
Show Gist options
  • Save jayd3e/e9b21ff49aafaf440db8 to your computer and use it in GitHub Desktop.
Save jayd3e/e9b21ff49aafaf440db8 to your computer and use it in GitHub Desktop.
#
# Pyramid is choosing this view
#
from pyramid.view import forbidden_view_config
from pyramid.httpexceptions import HTTPFound
@forbidden_view_config()
def login_redirect(request):
"""
This view redirects a user to the login page, and is a catch-all for
all Forbidden requests. In doing so it consistently changes the url
to '/login', which is desired.
"""
# store off the url we came from
request.session['came_from'] = request.url
return HTTPFound(location=request.route_url('login',
_app_url=request.registry.settings['clusterflunk.domain']))
#
# Over this one
#
from pyramid.view import (
forbidden_view_config
)
from clusterapp.api import (
api_exception_decorator_factory,
BadRequest
)
@forbidden_view_config(route_name='api_v1',
decorator=(api_exception_decorator_factory),
renderer='json')
def login_redirect_api(request):
raise BadRequest(status='failure',
code=1,
msg="user isn't logged in")
#
# When the route is
#
# Global
config.add_route('api_v1', '/api/1/*path')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment