comparison wiki/middleware.py @ 1174:ba3230aba90c

Fix unicode error with wiki cookie processing
author Brian Neal <bgneal@gmail.com>
date Thu, 07 Jun 2018 19:53:13 -0500
parents 47521d9e94bd
children
comparison
equal deleted inserted replaced
1173:a1a223ab0c8f 1174:ba3230aba90c
21 def cookie_value(user, now): 21 def cookie_value(user, now):
22 """Creates the value for the external wiki cookie.""" 22 """Creates the value for the external wiki cookie."""
23 23
24 # The key part of the cookie is just a string that would make things 24 # The key part of the cookie is just a string that would make things
25 # difficult for a spoofer; something that can't be easily made up: 25 # difficult for a spoofer; something that can't be easily made up:
26 username = user.username.encode('utf-8')
27 email = user.email.encode('utf-8')
26 28
27 h = hashlib.sha256() 29 h = hashlib.sha256()
28 h.update(user.username.encode('utf-8')) 30 h.update(username)
29 h.update(user.email.encode('utf-8')) 31 h.update(email)
30 h.update(now.isoformat()) 32 h.update(now.isoformat())
31 h.update(''.join(random.sample(string.printable, 64))) 33 h.update(''.join(random.sample(string.printable, 64)))
32 h.update(settings.SECRET_KEY) 34 h.update(settings.SECRET_KEY)
33 key = h.hexdigest() 35 key = h.hexdigest()
34 36
35 parts = (user.username, user.email, key) 37 parts = (username, email, key)
36 return '#'.join(parts) 38 return '#'.join(parts)
37 39
38 40
39 def create_wiki_session(request, response): 41 def create_wiki_session(request, response):
40 """Sets up the session for the external wiki application. 42 """Sets up the session for the external wiki application.