[Bugfix] 修改bug,使用py3编程

This commit is contained in:
GuangHongwei
2017-05-15 23:39:54 +08:00
parent 3c8d6fbe1b
commit 458989328e
13 changed files with 37 additions and 47 deletions

View File

@@ -161,10 +161,12 @@ def refresh_token(token, user, expiration=3600):
def generate_token(request, user):
expiration = settings.CONFIG.TOKEN_EXPIRATION or 3600
remote_addr = request.META.get('REMOTE_ADDR', '')
remote_addr = base64.b16encode(remote_addr).replace('=', '')
if not isinstance(remote_addr, bytes):
remote_addr = remote_addr.encode("utf-8")
remote_addr = base64.b16encode(remote_addr) #.replace(b'=', '')
token = cache.get('%s_%s' % (user.id, remote_addr))
if not token:
token = uuid.uuid4().get_hex()
token = uuid.uuid4().hex
print('Set cache: %s' % token)
cache.set(token, user.id, expiration)
cache.set('%s_%s' % (user.id, remote_addr), token, expiration)