1 from pyramid.response import Response
2 from pyramid.httpexceptions import HTTPForbidden, HTTPFound
3 from pyramid.security import remember, forget
4 from pyramid_persona.views import verify_login
5 from xonstat.models import *
7 def forbidden(request):
8 '''A simple forbidden view. Does nothing more than set the status and then
9 gets the heck out of dodge. The forbidden.mako template does the work.'''
10 request.response.status = 403
14 # Verify the assertion and get the email of the user
15 persona_email = verify_login(request)
17 # Check that the email exists in the players table
18 player_email = DBSession.query(Player).\
19 filter(Player.email_addr == persona_email).one()
21 log.debug("Verified email address: %s" % persona_email)
22 log.debug("Corresponding player is %s" % player_email)
24 if player_email is not None:
25 # Add the headers required to remember the user to the response
26 request.response.headers.extend(remember(request, persona_email))
28 url = request.route_url("forbidden")
29 return HTTPFound(location=url)
31 # Return a json message containing the address or path to redirect to.
32 return {'redirect': request.POST['came_from'], 'success': True}
35 '''A simple merge view. The merge.mako template does the work.'''