本文整理汇总了Python中models.user.User.lookup方法的典型用法代码示例。如果您正苦于以下问题:Python User.lookup方法的具体用法?Python User.lookup怎么用?Python User.lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.lookup方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_login
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import lookup [as 别名]
def _do_login(self, response):
username = self.get_argument("username", None)
password = self.get_argument("password", None)
if not username or not password:
# do something
self.flash.error = "You must enter a username and password to proceed. Please try again."
return
pw = hashlib.sha1(password).hexdigest()
username = User.normalize(username)
user = User.lookup(username)
#check the password.
if not user or user['password'] != pw:
# do something
self.flash.error = "Login not valid"
return
# check if user is suspended.
if user.is_suspended() :
self.flash.error = "Sorry the account you specified has been suspended."
return
user.history.last_login = datetime.datetime.utcnow()
Mongo.db.ui['users'].update({'_id': username}, {
'$set' : {'history.last_login': user.history.last_login},
'$inc' : {'history.num_logins' : 1}
})
#add to the session.
self.session['username'] = user._id
#check keep_logged_in
if self.get_argument("keep_logged_in", False) == "on" :
self.session['keep_logged_in'] = True
self.set_current_user(user)
# self.session['current_user']= user._id
self.flash.notice = "Welcome, %s" % user._id
self.write(username)
self.finish("finished")
示例2: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import lookup [as 别名]
def get(self):
if not self.get_secure_cookie('username'):
username = self.get_secure_cookie('username')
if username:
user = User.lookup(username)
if user:
self.session['username'] = user.username
self.session['locale'] = user.profile.locale
self.redirect("/")
else:
template_values = {}
template_values['next'] = self.get_argument('next', '/')
self.render_template('/account/login.html', **template_values)
示例3: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import lookup [as 别名]
def post(self):
username = self.get_argument("username", None)
password = self.get_argument("password", None)
if not username or not password:
# do something
self.flash.error = "You must enter a username and password to proceed. Please try again."
self.session["flash"] = self.flash
self.redirect("/login")
return
pw = hashlib.sha1(password).hexdigest()
username = User.normalize(username)
user = User.lookup(username)
# check the password.
if not user or user["password"] != pw:
# do something
self.flash.error = "Login not valid"
self.redirect("/login")
return
# check if user is suspended.
if user.is_suspended():
self.flash.error = "Sorry the account you specified has been suspended."
self.redirect("/")
return
user.history.last_login = datetime.datetime.utcnow()
Mongo.db.ui["users"].update(
{"_id": username},
{"$set": {"history.last_login": user.history.last_login}, "$inc": {"history.num_logins": 1}},
)
# add to the session.
self.session["username"] = user._id
# check keep_logged_in
# print self.get_arguments("keep_logged_in", False)
if self.get_argument("keep_logged_in", False) == "on":
self.session["keep_logged_in"] = True
self.set_current_user(user)
self.flash.notice = "Welcome, %s" % user._id
if user["roletype"] == 2:
self.redirect("/manage")
elif user["roletype"] == 3:
self.redirect("/product")
else:
self.redirect("/signup")
示例4: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import lookup [as 别名]
def post(self):
username = self.get_argument("username", None)
password = self.get_argument("password", None)
if not username or not password:
# do something
self.flash.error = "You must enter a username and password to proceed. Please try again."
self.session['flash'] = self.flash
self.redirect("/login")
return
pw = hashlib.sha1(password).hexdigest()
username = User.normalize(username)
user = User.lookup(username)
#check the password.
if not user or user['password'] != pw:
# do something
self.flash.error = "Login not valid"
self.redirect("/login")
return
# check if user is suspended.
if user.is_suspended() :
self.flash.error = "Sorry the account you specified has been suspended."
self.redirect("/")
return
user.history.last_login = datetime.datetime.utcnow()
Mongo.db.ui['users'].update({'_id': username}, {
'$set' : {'history.last_login': user.history.last_login},
'$inc' : {'history.num_logins' : 1}
})
#add to the session.
self.session['username'] = user._id
self.session['keep_logged_in'] = True
self.set_current_user(user)
self.flash.notice = "Welcome, %s" % user._id
forwardUrl = self.get_argument('next', '/')
self.redirect("/syslog")
示例5:
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import lookup [as 别名]
'''
示例6:
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import lookup [as 别名]
# -*- coding: utf-8 -*-