本文整理汇总了Python中model.User.find_first方法的典型用法代码示例。如果您正苦于以下问题:Python User.find_first方法的具体用法?Python User.find_first怎么用?Python User.find_first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.find_first方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_message
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def send_message():
i = ctx.request.input(to="", subject="", content="")
user_to = User.find_first("where t_emailaddr=?", i.to)
to_id = user_to.t_uid
from_id = ctx.request.user.t_uid
subject = valid_secure_data(i.subject)
content = valid_secure_data(i.content)
msg = Message(t_to=to_id, t_from=from_id, t_title=subject, t_content=content, t_read=0, t_time=time.time())
msg.insert()
return dict()
示例2: user_login
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def user_login(email, password, remember, max_age=604800):
'''
Log in a user
'''
user = User.find_first('where t_email=?', email)
if not user:
return False
if user.password.lower() != password.lower():
return False
cookie = make_signed_cookie(str(user.t_uid), user.t_password, max_age)
ctx.response.set_cookie(_COOKIE_NAME, cookie, max_age=(max_age if remember else None))
return user
示例3: api_add_friend
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def api_add_friend():
current_user = ctx.request.user
current_peerlist = PeerList.find_first("where t_uid=?", current_user.t_uid)
i = ctx.request.input(email="")
target_email = valid_secure_data(i.email)
if not target_email:
raise APIValueError("email", "Empty email address")
target_user = User.find_first("where t_emailaddr=?", target_email)
if target_user is None:
raise APIValueError("email", "User doesn't exist.")
current_peerlist.t_friends += ";" + str(target_user.t_uid)
current_peerlist.update()
return dict()
示例4: api_get_friendlist
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def api_get_friendlist():
current_user = ctx.request.user
friends_dataobj = PeerList.find_first("where t_uid=?", current_user.t_uid)
friends_str = friends_dataobj.t_friends
flist = re.split(";", friends_str)
count = len(flist)
page = Page(count, _get_page_index(), page_size=5)
friends = list()
for uid in flist:
u = User.find_first("where t_uid=? order by t_uid desc limit ?,?", uid, page.offset, page.limit)
if u is None:
continue
friends.append(u)
return dict(user=current_user, friends=friends, page=page)
示例5: authenticate
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def authenticate():
i = ctx.request.input()
email = i.email.strip()
password = i.password
user = User.find_first('where email = ?', email)
if user is None:
raise APIPermissionError('invalid email. please sign up first')
elif user.password != password:
raise APIPermissionError('password not correct')
max_age = 604800
cookie = make_signed_cookie(user.id, user.password, max_age)
logging.info('cookie %s:%s' % (_COOKIE_NAME, cookie))
ctx.response.set_cookie(_COOKIE_NAME, cookie, max_age = max_age)
user.password = '********'
return user
示例6: receive_message
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def receive_message():
user = ctx.request.user
if not user:
return dict()
uid = user.t_uid
total = Message.count_by("where t_to=?", uid)
page = Page(total, page_index=_get_page_index(), page_size=5)
msg_list = Message.find_by("where t_to=? order by t_time desc limit ?,?", uid, page.offset, page.limit)
messages = list()
for m in msg_list:
u = User.find_first("where t_uid=?", m.t_from)
m.t_from = u.t_username
m["t_fromid"] = u.t_uid
m["t_fromemail"] = u.t_emailaddr
messages.append(m)
return dict(messages=messages, page=page)
示例7: register_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def register_user():
i = ctx.request.input(name='',email='', password='')
name = i.name.strip()
email = i.email.strip()
password = i.password
if not name:
raise APIValueError('name')
if not email or not email_valid(email):
raise APIValueError('email')
if not password or not password_valid(password):
raise APIValueError('password')
user = User.find_first('where email=?', email)
if user:
raise APIError('registered failed', 'email', 'Email is already in use')
user = User(name = name, email = email, password = password, image = 'about:blank')
user.insert()
return user
示例8: parse_signed_cookie
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def parse_signed_cookie(cookie_str):
'''
Parse and identify the cookie retrieved.
'''
try:
L = cookie_str.split('-')
if len(L) != 3:
return None
id, expires, md5 = L
if int(expires) < time.time():
return None
user = User.find_first('where t_uid=?', id)
if user is None:
return None
if md5 != hashlib.md5('%s-%s-%s-%s' % (id, user.t_password, expires, _COOKIE_KEY)).hexdigest():
return None
return user
except Exception, e:
logging.info(e.message)
return None
示例9: user_register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
def user_register(email, password, username, captcha, answer):
'''
Register a user. And if success it will be logged in automatically.
'''
if answer.lower() != captcha.lower():
raise APIValueError('captcha', 'Wrong Captcha - ' + captcha)
if not username:
raise APIValueError('username', message="Username cannot be empty.")
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email', message="Email cannot be empty.")
if not password or not _RE_MD5.match(password):
raise APIValueError('password', message="Invalid Hashvalue")
user = User.find_first('where t_emailaddr=?', email)
if user:
raise APIValueError('email', message="EMail is already in use.")
# Write to database
user = User(username=username, email=email, password=password,
avatar='/resources/images/user_default.gif', creation_time=time.time())
current_user = user.insert()
# Login as registered user.
cookie = make_signed_cookie(str(current_user['t_uid']), user.password, None)
ctx.response.set_cookie(_COOKIE_NAME, cookie)
return current_user
示例10: User
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import logging
logging.basicConfig(format='%(levelname)s:%(message)s',level='INFO')
from model import User,Blog,Comment
import db
db.create_engine(user='root',password='123456',database='myblog')
u = User(name = 'Test',email='[email protected]',password='123456',image='about:blank')
u.insert()
print 'new user id:',u.id
u1 = User.find_first('where email=?',['[email protected]'])
print 'find user\'s name:',u1.name
示例11: Name
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import find_first [as 别名]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2016-06-27 17:46:50
# @Author : Your Name ([email protected])
# @Link : http://example.org
# @Version : $Id$
from model import User, Blog, Comment
from transwarp import db
db.create_engine(user='root', password='root', database='awesome')
u = User(name='Test2', email='[email protected]', password='1234567890', image='about:blank')
#u.insert()
#print 'new user id:', u.id
u1 = User.find_first('where email=?', '[email protected]')
print 'find user\'s name:', u1.name
#u1.delete()
u2 = User.find_first('where email=?', '[email protected]')
print 'find user:', u2