代码拉取完成,页面将自动刷新
同步操作将从 thanatosx/WebBlog 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import hashlib
import logging
import asyncio
import time
from config.config_util import config
from domain import User
__author__ = 'thanatos'
__COOKIE_KEY = config.session.secret
def user2cookie(user, max_age):
"""
Generate cookie str by user.
"""
# build cookie string by: id-expires-sha1
expires = str(int(time.time() + max_age))
s = '%s-%s-%s-%s' % (user.id, user.password, expires, __COOKIE_KEY)
user_auth_cookie = [str(user.id), expires, hashlib.md5(s.encode('utf-8')).hexdigest()]
return '-'.join(user_auth_cookie)
@asyncio.coroutine
def cookie2user(cookie_str):
"""
Parse cookie and load user if cookie is valid.
"""
if not cookie_str:
return None
try:
L = cookie_str.split('-')
if len(L) != 3:
return None
uid, expires, sha1 = L
if int(expires) < time.time():
return None
user = yield from User.find(uid)
if user is None:
return None
s = '%s-%s-%s-%s' % (uid, user.password, expires, __COOKIE_KEY)
if sha1 != hashlib.md5(s.encode('utf-8')).hexdigest():
logging.info('invalid sha1')
return None
return user
except Exception as e:
logging.exception(e)
return None
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。