view pinlib/pinlib.py @ 132:99e4022eae52

pics3: add Dockerfile and requirements.pip
author paulo
date Thu, 20 Jan 2022 01:28:46 -0800
parents d7d67887102f
children
line source
1 import urlparse
4 def parse_cookies(environ):
5 return urlparse.parse_qs(environ.get("HTTP_COOKIE", "").replace("; ", "&"))
8 class PinFailError(Exception):
9 pass
12 class PinMan(object):
13 def __init__(self, key):
14 assert key
15 self._key = key
16 self._fn = "_%s" % key
18 def load(self):
19 ret = None
21 try:
22 with open(self._fn) as pin_f:
23 ret = pin_f.read().strip()
24 except IOError:
25 pass
27 return ret
29 def check(self, cookies):
30 if self._key not in cookies:
31 raise PinFailError()
33 pin = cookies[self._key][0]
34 if pin != self.load():
35 raise PinFailError()
37 return pin