本文整理汇总了Python中models.users.Users.get_user_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Users.get_user_by_id方法的具体用法?Python Users.get_user_by_id怎么用?Python Users.get_user_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.users.Users
的用法示例。
在下文中一共展示了Users.get_user_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseHandler
# 需要导入模块: from models.users import Users [as 别名]
# 或者: from models.users.Users import get_user_by_id [as 别名]
class BaseHandler(tornado.web.RequestHandler):
def __init__(self, application, request, **kwargs):
super(BaseHandler, self).__init__(application, request, **kwargs)
self.users_ins = Users()
self.files_ins = Files()
self.posts_ins = Posts()
self.admin_ins = Admin()
self.confs_ins = Confs()
self.terms_ins = Terms()
self.links_ins = Links()
self.talks_ins = Talks()
self.email_ins = Email()
# 重写get_current_user, 主要实现当前登陆用户获取
def get_current_user(self):
usid = self.get_cookie('_usid')
auid = self.get_secure_cookie('_auid')
auth = self.get_secure_cookie('_auth')
if usid and auth:
user = self.users_ins.get_user_by_id(usid)
if user and user['user_auid'] == auid and Tools.generate_authword(user['user_atms'], user['user_salt']) == auth:
return user
# 获取当前运行时段的配置
def get_runtime_conf(self, name):
# return self.confs_ins.obtain_conf_by_name(name)
return ""
def jsons(self, json):
if json is None or json == '':
return None
return tornado.escape.json_decode(json)
def flash(self, isok, resp=None, _ext=''): # 异常抛出处理
if resp is None:
resp = {}
if isok:
resp['err'] = 0
else:
resp['err'] = 1
if 'sta' in resp and resp['sta']:
self.set_status(resp['sta'])
else:
resp['sta'] = self.get_status()
if 'msg' not in resp:
resp['msg'] = self._reason
if 'url' not in resp:
resp['url'] = ''
if 'dat' not in resp:
resp['dat'] = {}
if _ext == '.json' or self.find_accept('json'):
self.write(tornado.escape.json_encode(resp))
else:
self.render('flash.html', resp=resp)
def find_accept(self, name):
return 'Accept' in self.request.headers and self.request.headers['Accept'].find(name) >= 0
def human_valid(self): # 验证码
field = '_code'
value = self.get_secure_cookie(field)
if value:
self.clear_cookie(field)
str_input = self.get_argument(field, None)
if str_input:
value = tornado.escape.json_decode(value)
return 'time' in value and 'code' in value \
and 0 < int(time.time()) - value['time'] < 60 \
and value['code'] == Utils.str_md5_hex(Utils.str_md5_hex(self.settings['cookie_secret']) + str_input + str(value['time']))
return False
def entry(self, sign, size=1, life=10, swap=False): # 控制登陆尝试次数
sign = '[email protected]' + sign
data = Cache.obtain(sign)
if swap or not data:
Cache.upsert(sign, size, life)
return data
def set_current_sess(self, user, days=30):
self.set_cookie('_usid', str(user['user_id']), expires_days=days)
self.set_secure_cookie('_auid', str(user['user_auid']), expires_days=days, httponly=True)
self.set_secure_cookie('_auth', Tools.generate_authword(user['user_atms'], user['user_salt']))
def del_current_sess(self):
self.clear_cookie("_auid")
self.clear_cookie("_auth")
def utils(self):
return Utils
def tourl(self, args, base=None):
if base is None:
base = self.request.path
return tornado.httputil.url_concat(base, args)
#.........这里部分代码省略.........