]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Move the blind_id verification function to util.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 11 Aug 2013 14:08:28 +0000 (10:08 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 11 Aug 2013 14:08:28 +0000 (10:08 -0400)
Before the only view that was using this function was the
submission view. That is no longer going to be the case, so the
function should be moved to a general purpose area. Util is the
best place for that!

xonstat/util.py
xonstat/views/submission.py

index 8af24efc1a16ec7c75d8da08c1476c9185dfba9c..d8599303c324f332cf3dbbbe38c568989834c002 100644 (file)
@@ -1,9 +1,16 @@
+import logging
+import pyramid.httpexceptions
 import re
 from colorsys import rgb_to_hls, hls_to_rgb
 from cgi import escape as html_escape
 from datetime import datetime, timedelta
 from decimal import Decimal
 from collections import namedtuple
+from xonstat.d0_blind_id import d0_blind_id_verify
+
+
+log = logging.getLogger(__name__)
+
 
 # Map of special chars to ascii from Darkplace's console.c.
 _qfont_table = [
@@ -237,3 +244,31 @@ def is_cake_day(create_dt, today_dt=None):
                 cake_day = True
 
     return cake_day
+
+
+def verify_request(request):
+    """Verify requests using the d0_blind_id library"""
+
+    # first determine if we should be verifying or not
+    val_verify_requests = request.registry.settings.get('xonstat.verify_requests', 'true')
+    if val_verify_requests == "true":
+        flg_verify_requests = True
+    else:
+        flg_verify_requests = False
+
+    try:
+        (idfp, status) = d0_blind_id_verify(
+                sig=request.headers['X-D0-Blind-Id-Detached-Signature'],
+                querystring='',
+                postdata=request.body)
+
+        log.debug('\nidfp: {0}\nstatus: {1}'.format(idfp, status))
+    except:
+        idfp = None
+        status = None
+
+    if flg_verify_requests and not idfp:
+        log.debug("ERROR: Unverified request")
+        raise pyramid.httpexceptions.HTTPUnauthorized("Unverified request")
+
+    return (idfp, status)
index 6c035fef30e2db76a095a066694968c98d02a5df..7442c80f086025c914fe7ae309fcb06b5bc603cd 100644 (file)
@@ -8,10 +8,9 @@ import sqlalchemy.sql.expression as expr
 from pyramid.response import Response\r
 from sqlalchemy import Sequence\r
 from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound\r
-from xonstat.d0_blind_id import d0_blind_id_verify\r
 from xonstat.elo import process_elos\r
 from xonstat.models import *\r
-from xonstat.util import strip_colors, qfont_decode\r
+from xonstat.util import strip_colors, qfont_decode, verify_request\r
 \r
 \r
 log = logging.getLogger(__name__)\r
@@ -167,34 +166,6 @@ def is_supported_gametype(gametype, version):
     return is_supported\r
 \r
 \r
-def verify_request(request):\r
-    """Verify requests using the d0_blind_id library"""\r
-\r
-    # first determine if we should be verifying or not\r
-    val_verify_requests = request.registry.settings.get('xonstat.verify_requests', 'true')\r
-    if val_verify_requests == "true":\r
-        flg_verify_requests = True\r
-    else:\r
-        flg_verify_requests = False\r
-\r
-    try:\r
-        (idfp, status) = d0_blind_id_verify(\r
-                sig=request.headers['X-D0-Blind-Id-Detached-Signature'],\r
-                querystring='',\r
-                postdata=request.body)\r
-\r
-        log.debug('\nidfp: {0}\nstatus: {1}'.format(idfp, status))\r
-    except:\r
-        idfp = None\r
-        status = None\r
-\r
-    if flg_verify_requests and not idfp:\r
-        log.debug("ERROR: Unverified request")\r
-        raise pyramid.httpexceptions.HTTPUnauthorized("Unverified request")\r
-\r
-    return (idfp, status)\r
-\r
-\r
 def do_precondition_checks(request, game_meta, raw_players):\r
     """Precondition checks for ALL gametypes.\r
        These do not require a database connection."""\r