本文整理汇总了Python中models.user.User.get_by_username方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_username方法的具体用法?Python User.get_by_username怎么用?Python User.get_by_username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.get_by_username方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_login_action_after_activation
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_username [as 别名]
def test_login_action_after_activation():
user = User.get_by_username("marcora")
assert user.activation_code
res = app.get("/activate/" + user.activation_code)
user = User.get_by_username("marcora")
assert not user.activation_code
res = app.post("/login", {"username": "marcora", "password": "654321"})
assert res.json == "authenticate"
res = app.post("/login", {"username": "marcora", "password": "123456"})
assert res.json == "authenticated"
示例2: wrapper
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_username [as 别名]
def wrapper(self, *args, **kwargs):
user = None
cookie = Cookie.SimpleCookie(self.request.headers.get('Cookie'))
if cookie.has_key('pubmedos_sid'):
sid = cookie['pubmedos_sid'].value
if sid:
session = memcache.get(sid)
if session:
username = session.get('username')
remote_addr = session.get('remote_addr')
if username and self.request.remote_addr == remote_addr:
user = User.get_by_username(username)
self.current_user = user
if not self.current_user:
self.error(401)
else:
request_handler(self, *args, **kwargs)
示例3: register
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_username [as 别名]
def register():
try:
username = request.form['username']
passwd = request.form['passwd']
nickname = request.form['nickname']
gender = request.form['gender']
birthday = request.form['birthday']
avatar_url = request.form['avatar_url']
if len(username)==0 or len(passwd)==0:
raise(KeyError)
except KeyError:
return error(400, u'参数错误')
if len(gender) == 0:
gender = 0
if len(birthday) == 0:
birthday = '1990-1-1'
if User.get_by_username(username):
return error(10008, u'用户已存在')
passwd = md5.new(passwd).hexdigest()
user = User.create(username, passwd, nickname, gender, birthday, avatar_url)
if not user:
return error(10007, u'创建失败')
return user
示例4: setup
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import get_by_username [as 别名]
def setup():
user = User.get_by_username('marcora')
folder = Folder.get_or_insert_by_user_and_title(user, 'Foo')
res = app.post('/login', {'username':'marcora', 'password':'123456'})