comparison service/frontDoorLock/front_door_lock.py @ 1380:7229daca9c9a

simple api checks for (any) user too Ignore-this: 84192f452f44ba481f77629bf065f2d1 darcs-hash:f1b3dc8be5cefd577c09268c2564645c6529c22c
author drewp <drewp@bigasterisk.com>
date Mon, 06 May 2019 21:11:00 -0700
parents baf1acaa9ac9
children 013e2a89b345
comparison
equal deleted inserted replaced
1379:baf1acaa9ac9 1380:7229daca9c9a
37 def stateFromMqtt(msg: bytes): 37 def stateFromMqtt(msg: bytes):
38 return { 38 return {
39 b'OFF': ROOM['locked'], 39 b'OFF': ROOM['locked'],
40 b'ON': ROOM['unlocked'], 40 b'ON': ROOM['unlocked'],
41 }[bytes(msg)] 41 }[bytes(msg)]
42 42
43 def requestUser(req):
44 # what happened to the case-insens dict?
45 h = dict((k.lower(), v) for k,v in req.headers.items())
46 return URIRef(h['x-foaf-agent'])
47
48
43 class OutputPage(cyclone.web.RequestHandler): 49 class OutputPage(cyclone.web.RequestHandler):
44 def put(self): 50 def put(self):
45 try: 51 try:
46 # what happened to the case-insens dict? 52 user = requestUser(self.request)
47 h = dict((k.lower(), v) for k,v in self.request.headers.items())
48 user = URIRef(h['x-foaf-agent'])
49 except KeyError: 53 except KeyError:
50 log.warn('request without x-foaf-agent: %s', h) 54 log.warn('request without x-foaf-agent: %s', h)
51 self.set_status(403, 'need x-foaf-agent') 55 self.set_status(403, 'need x-foaf-agent')
52 return 56 return
53 arg = self.request.arguments 57 arg = self.request.arguments
76 return 80 return
77 log.warn("ignoring %s", stmt) 81 log.warn("ignoring %s", stmt)
78 82
79 class SimpleState(cyclone.web.RequestHandler): 83 class SimpleState(cyclone.web.RequestHandler):
80 def post(self): 84 def post(self):
85 try:
86 user = requestUser(self.request)
87 except KeyError:
88 log.warn('request without x-foaf-agent: %s', h)
89 self.set_status(403, 'need x-foaf-agent')
90 return
91
81 state = self.request.body.strip().decode('ascii') 92 state = self.request.body.strip().decode('ascii')
82 if state == 'unlock': 93 if state == 'unlock':
83 self.settings.autoLock.onUnlockedStmt() 94 self.settings.autoLock.onUnlockedStmt()
84 self.settings.mqtt.publish(espName + b"/switch/strike/command", b'ON') 95 self.settings.mqtt.publish(espName + b"/switch/strike/command", b'ON')
85 if state == 'lock': 96 if state == 'lock':