Mercurial > hg > index.fcgi > www > www-1
view laterlinks2/pinlib.py @ 79:01cf0e93c914
cs: fix cookie paths
author | paulo |
---|---|
date | Thu, 02 Jun 2016 01:51:04 -0600 |
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