view laterlinks2/pinlib.py @ 78:f833a888c548

add cookie-based PIN system, and update laterlinks to use it
author paulo
date Thu, 02 Jun 2016 00:27:50 -0700
parents
children
line source
1 import urlparse
4 PIN_KEY = "llpin"
5 PIN_FN = "_%s" % PIN_KEY
8 class PinFailError(Exception):
9 pass
12 def load():
13 ret = None
15 try:
16 with open(PIN_FN) as pin_f:
17 ret = pin_f.read().strip()
18 except IOError:
19 pass
21 return ret
24 def parse_cookies(environ):
25 return urlparse.parse_qs(environ.get("HTTP_COOKIE", ""))
28 def check(cookies):
29 if PIN_KEY not in cookies:
30 raise PinFailError()
32 pin = cookies[PIN_KEY][0]
33 if pin != load():
34 raise PinFailError()
36 return pin