Mercurial > hg > index.fcgi > www > www-1
comparison laterlinks2/pinlib.py @ 79:01cf0e93c914
cs: fix cookie paths
author | paulo |
---|---|
date | Thu, 02 Jun 2016 01:51:04 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a68e5533ad83 |
---|---|
1 import urlparse | |
2 | |
3 | |
4 PIN_KEY = "llpin" | |
5 PIN_FN = "_%s" % PIN_KEY | |
6 | |
7 | |
8 class PinFailError(Exception): | |
9 pass | |
10 | |
11 | |
12 def load(): | |
13 ret = None | |
14 | |
15 try: | |
16 with open(PIN_FN) as pin_f: | |
17 ret = pin_f.read().strip() | |
18 except IOError: | |
19 pass | |
20 | |
21 return ret | |
22 | |
23 | |
24 def parse_cookies(environ): | |
25 return urlparse.parse_qs(environ.get("HTTP_COOKIE", "")) | |
26 | |
27 | |
28 def check(cookies): | |
29 if PIN_KEY not in cookies: | |
30 raise PinFailError() | |
31 | |
32 pin = cookies[PIN_KEY][0] | |
33 if pin != load(): | |
34 raise PinFailError() | |
35 | |
36 return pin |