]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/views/admin.py
Add basic merge view with admin group membership required.
[xonotic/xonstat.git] / xonstat / views / admin.py
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 *
6
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
11     return {}
12
13 def login(request):
14     # Verify the assertion and get the email of the user
15     persona_email = verify_login(request)
16
17     # Check that the email exists in the players table
18     player_email = DBSession.query(Player).\
19             filter(Player.email_addr == persona_email).one()
20
21     log.debug("Verified email address: %s" % persona_email)
22     log.debug("Corresponding player is %s" % player_email)
23
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))
27     else:
28         url = request.route_url("forbidden")
29         return HTTPFound(location=url)
30
31     # Return a json message containing the address or path to redirect to.
32     return {'redirect': request.POST['came_from'], 'success': True}
33
34 def merge(request):
35     '''A simple merge view. The merge.mako template does the work.'''
36     return {}