]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add actual merge functionality.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 18 Jun 2014 01:04:39 +0000 (21:04 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 18 Jun 2014 01:04:39 +0000 (21:04 -0400)
xonstat/templates/merge.mako
xonstat/views/admin.py

index 49d389b8d5302a37d71f6c93453ecab3defe120a..9704f212e68ca9df6aa0307e995e302cecfb37d4 100644 (file)
@@ -33,7 +33,7 @@ ${nav.nav('players')}
         <!-- Form submitted? -->
         <input type="hidden" name="fs" />
 
-        <input type="hidden" name="csrf_token" value=${request.session.get_csrf_token()}/>
+        <input type="hidden" name="csrf_token" value="${request.session.get_csrf_token()}"/>
 
         <!-- Button -->
         <div class="control-group">
index a1516bc8b53dce3c6c0b737756942cb445415821..520f779c03e47d53b960e9eae2b1fd4ce63351b5 100644 (file)
@@ -1,6 +1,7 @@
 from pyramid.response import Response
 from pyramid.httpexceptions import HTTPForbidden, HTTPFound
 from pyramid.security import remember, forget
+from pyramid.session import check_csrf_token
 from pyramid_persona.views import verify_login
 from xonstat.models import *
 
@@ -31,6 +32,31 @@ def login(request):
     # Return a json message containing the address or path to redirect to.
     return {'redirect': request.POST['came_from'], 'success': True}
 
+
 def merge(request):
     '''A simple merge view. The merge.mako template does the work.'''
+    s = DBSession()
+
+    # only do a merge if we have all of the required data
+    if request.params.has_key("csrf_token"):
+        # check the token to prevent request forgery
+        st = request.session.get_csrf_token()
+        log.debug("Session token is %s" % st)
+        log.debug("Request token is %s" % request.params.get('csrf_token'))
+        check_csrf_token(request)
+
+        if request.params.has_key("w_pid") and request.params.has_key("l_pid"):
+            w_pid = request.params.get("w_pid")
+            l_pid = request.params.get("l_pid")
+
+            # do the merge, hope for the best!
+            try:
+                s.execute("select merge_players(:w_pid, :l_pid)",
+                    {"w_pid": w_pid, "l_pid": l_pid})
+
+                s.commit()
+
+            except:
+                s.rollback()
+
     return {}