changeset 577:759bf29d9dbe

simple api checks for (any) user too Ignore-this: 84192f452f44ba481f77629bf065f2d1
author drewp@bigasterisk.com
date Mon, 06 May 2019 21:11:00 -0700
parents 150aa09c9723
children 60f6d5c61003
files service/frontDoorLock/front_door_lock.py
diffstat 1 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/service/frontDoorLock/front_door_lock.py	Mon May 06 21:07:42 2019 -0700
+++ b/service/frontDoorLock/front_door_lock.py	Mon May 06 21:11:00 2019 -0700
@@ -39,13 +39,17 @@
         b'OFF': ROOM['locked'],
         b'ON': ROOM['unlocked'],
     }[bytes(msg)]
+
+def requestUser(req):
+    # what happened to the case-insens dict?
+    h = dict((k.lower(), v) for k,v in req.headers.items())
+    return URIRef(h['x-foaf-agent'])
     
+
 class OutputPage(cyclone.web.RequestHandler):
     def put(self):
         try:
-            # what happened to the case-insens dict?
-            h = dict((k.lower(), v) for k,v in self.request.headers.items())
-            user = URIRef(h['x-foaf-agent'])
+            user = requestUser(self.request)
         except KeyError:
             log.warn('request without x-foaf-agent: %s', h)
             self.set_status(403, 'need x-foaf-agent')
@@ -78,6 +82,13 @@
 
 class SimpleState(cyclone.web.RequestHandler):
     def post(self):
+        try:
+            user = requestUser(self.request)
+        except KeyError:
+            log.warn('request without x-foaf-agent: %s', h)
+            self.set_status(403, 'need x-foaf-agent')
+            return
+        
         state = self.request.body.strip().decode('ascii')
         if state == 'unlock':
             self.settings.autoLock.onUnlockedStmt()