forked from ctb/meep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meepcookie.py
38 lines (28 loc) · 906 Bytes
/
meepcookie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from Cookie import SimpleCookie
from mysqlConnection import con, cur
import uuid
def make_set_cookie_header(name, value, path='/'):
"""
Makes a 'Set-Cookie' header.
"""
sessionID = str(uuid.uuid4())
c = SimpleCookie()
c[name] = sessionID
c[name]['path'] = path
#insert entry into database
cur.execute("""INSERT INTO SESSION(ID, USER_ID) VALUES('%s',
%d)""" % (sessionID, value.id))
con.commit()
# can also set expires and other stuff. See
# Examples under http://docs.python.org/library/cookie.html.
s = c.output()
(key, value) = s.split(': ')
return (key, value)
def destroyCookieHeader(id):
cur.execute("""DELETE FROM SESSION WHERE ID='%s'""" % (id))
con.commit()
c = SimpleCookie()
c['username'] = ''
s = c.output()
(key, value) = s.split(': ')
return (key, value)