# HG changeset patch # User drewp@bigasterisk.com # Date 1557202260 25200 # Node ID 759bf29d9dbe7e0ba2752750907500d975fae43b # Parent 150aa09c9723be9aa0319757d5e5c9ee2b64e9fc simple api checks for (any) user too Ignore-this: 84192f452f44ba481f77629bf065f2d1 diff -r 150aa09c9723 -r 759bf29d9dbe service/frontDoorLock/front_door_lock.py --- 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()