Author: humbedooh
Date: Fri Mar 20 20:09:42 2015
New Revision: 1668140

URL: http://svn.apache.org/r1668140
Log:
- add a voter tool lib (mainly for getting/setting UIDs)
- remove unused karma code

Added:
    steve/trunk/pytest/www/cgi-bin/lib/voter.py
Modified:
    steve/trunk/pytest/www/cgi-bin/rest_admin.py
    steve/trunk/pytest/www/cgi-bin/rest_voter.py

Added: steve/trunk/pytest/www/cgi-bin/lib/voter.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/lib/voter.py?rev=1668140&view=auto
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/lib/voter.py (added)
+++ steve/trunk/pytest/www/cgi-bin/lib/voter.py Fri Mar 20 20:09:42 2015
@@ -0,0 +1,40 @@
+import hashlib, json, random
+from __main__ import homedir
+
+def get(election, basedata, uid):
+    elpath = os.path.join(homedir, "issues", election)
+    with open(elpath + "/voters.json", "r") as f:
+        voters = json.loads(f.read())
+        f.close()
+        xhash = hashlib.sha512(basedata['hash'] + uid)
+        for voter in voters:
+            if voters[voter] == xhash:
+                return voter
+    return None
+        
+def add(election, basedata, email):
+    uid = hashlib.sha512(email + basedata['hash'] + time.time() + 
random.randint(1,99999999))
+    xhash = hashlib.sha512(basedata['hash'] + uid)
+    elpath = os.path.join(homedir, "issues", election)
+    with open(elpath + "/voters.json", "r") as f:
+        voters = json.loads(f.read())
+        f.close()
+    with open(elpath + "/voters.json", "w") as f:
+        f.write(json.dumps(voters))
+        f.close()
+    return uid, xhash
+
+def remove(election, basedata, email):
+    uid = hashlib.sha512(email + basedata['hash'] + time.time() + 
random.randint(1,99999999))
+    xhash = hashlib.sha512(basedata['hash'] + uid)
+    elpath = os.path.join(homedir, "issues", election)
+    with open(elpath + "/voters.json", "r") as f:
+        voters = json.loads(f.read())
+        f.close()
+    if email in voters:
+        del voters[email]
+    with open(elpath + "/voters.json", "w") as f:
+        f.write(json.dumps(voters))
+        f.close()
+    return uid, xhash
+

Modified: steve/trunk/pytest/www/cgi-bin/rest_admin.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_admin.py?rev=1668140&r1=1668139&r2=1668140&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_admin.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_admin.py Fri Mar 20 20:09:42 2015
@@ -29,8 +29,7 @@ sys.path.append(path)
 sys.path.append(os.path.basename(sys.argv[0]))
 if 'SCRIPT_FILENAME' in os.environ:
     sys.path.insert(0, os.path.basename(os.environ['SCRIPT_FILENAME']))
-    
-from lib import response
+
 
 # Fetch config (hack, hack, hack)
 config = configparser.RawConfigParser()
@@ -43,6 +42,8 @@ form = cgi.FieldStorage();
 
 whoami = os.environ['REMOTE_USER'] if 'REMOTE_USER' in os.environ else None
 
+from lib import response, voter
+
 if not whoami:
     response.respond(403, {'message': 'Could not verify your identity: No auth 
scheme found'})
 elif not config.has_option('karma', whoami):

Modified: steve/trunk/pytest/www/cgi-bin/rest_voter.py
URL: 
http://svn.apache.org/viewvc/steve/trunk/pytest/www/cgi-bin/rest_voter.py?rev=1668140&r1=1668139&r2=1668140&view=diff
==============================================================================
--- steve/trunk/pytest/www/cgi-bin/rest_voter.py (original)
+++ steve/trunk/pytest/www/cgi-bin/rest_voter.py Fri Mar 20 20:09:42 2015
@@ -30,9 +30,6 @@ sys.path.append(path)
 sys.path.append(os.path.basename(sys.argv[0]))
 if 'SCRIPT_FILENAME' in os.environ:
     sys.path.insert(0, os.path.basename(os.environ['SCRIPT_FILENAME']))
-    
-from lib import response
-
 
 # Fetch config (hack, hack, hack)
 config = configparser.RawConfigParser()
@@ -43,11 +40,9 @@ homedir = config.get("general", "homedir
 pathinfo = os.environ['PATH_INFO'] if 'PATH_INFO' in os.environ else None
 form = cgi.FieldStorage();
 
+from lib import response, voter
 
 
-# TODO: Authentication goes here
-karma = 5 # assume admin karma for now
-
 # Figure out what to do and where
 if pathinfo:
     l = pathinfo.split("/")


Reply via email to