本文整理汇总了Python中model.User.findAll方法的典型用法代码示例。如果您正苦于以下问题:Python User.findAll方法的具体用法?Python User.findAll怎么用?Python User.findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.findAll方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def index(request):
users = yield from User.findAll();
print(users);
return {
'__template__': 'test.html',
'users':users
}
示例2: api_register
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def api_register(*, name, email, passwd):
r = web.Response()
if not name or not name.strip():
raise APIValueError('name')
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
users = yield from User.findAll('email=?', [email])
if len(users) > 0:
result = APIResult(0, '', 'Email is already in use.')
else:
sha1_passwd = '%s:%s' % ('hearain', passwd)
user = User(name=name.strip(),
email=email,
password=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(),
logo='http://www.gravatar.com/avatar/%s?d=wavatar&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest()
)
id = yield from user.save()
#设置session
config['_session'][user.email] = user2cookie(user, 86400)
setWebCookie(r, 'user', config['_session'][user.email])
setWebCookie(r, 'email', user.email)
setWebCookie(r, 'id', id)
setWebCookie(r, 'name', user.name)
result = APIResult(1, '', '')
return jsonResult(r, result)
示例3: api_login
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def api_login(*, email, passwd, yzcode):
r = web.Response()
if not email or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
if len(yzcode) > 0:
if yzcode.lower() != config['verify'].lower():
result = APIResult(0, '', '验证码错误')
else:
users = yield from User.findAll('email=?', [email])
if len(users) > 0:
sha1_passwd = '%s:%s' % ('hearain', passwd)
passwd = hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest()
if users[0].password == passwd:
# 设置session和cookie
config['_session'][email] = user2cookie(users[0], 86400)
setWebCookie(r, 'user', config['_session'][users[0].email])
setWebCookie(r, 'email', users[0].email)
setWebCookie(r, 'id', users[0].id)
setWebCookie(r, 'name', users[0].name)
result = APIResult(1, '', '')
else:
result = APIResult(0, '', '密码错误')
else:
result = APIResult(0, '', '邮箱不存在')
else:
result = APIResult(0, '', '验证码错误')
return jsonResult(r, result)
示例4: api_register_user
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def api_register_user(*,email,name,passwd):
logging.info('comming into register post users')
if not name or not name.strip():
raise APIValueError('name')
if not name or not _RE_EMAIL.match(email):
raise APIValueError('email')
if not passwd or not _RE_SHA1.match(passwd):
raise APIValueError('passwd')
users = yield from User.findAll('email=?',[email])
if len(users) > 0 :
raise APIError('register:failed','email','Email is already in use.')
uid = next_id()
sha1_passwd = '%s:%s' %(uid,passwd)
user = User(id=uid,name=name.strip(),email=email,passwd=hashlib.sha1(
sha1_passwd.encode('utf-8')).hexdigest(),image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
yield from user.save()
#make session cookie from here:
r = web.Response()
r.set_cookie(COOKIE_NAME,user2cookie(user,86400),max_age=86400,httponly=True)
user.passwd = '******'
r.content_type = 'application/json'
r.body = json.dumps(user,ensure_ascii=False).encode('utf-8')
return r
示例5: authenticate
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def authenticate(*, email, passwd):
if not email or re.match(_RE_EMAIL,email) is None:
raise APIValueError('email', 'invalid email')
if not passwd:
raise APIValueError('passwd', 'invalid passwd')
users = yield from User.findAll('email=?', [email])
if len(users) < 0:
return APIValueError('email', 'Email is not exist')
user = users[0]
sha1 = hashlib.sha1()
sha1.update(user.id.encode('utf-8'))
sha1.update(b':')
sha1.update(passwd.encode('utf-8'))
if user.passwd != sha1.hexdigest():
raise APIValueError('passwd', 'invalid passwd')
r = web.Response()
r.set_cookie(__COOKIE_NAME, user2cookie(
user, 86400), max_age=86400, httponly=True)
user.passwd = '******'
r.content_type = 'application/json'
r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
return r
示例6: authenticate
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def authenticate(*, email, passwd):
if not email:
raise APIValueError('email', 'Invalid email.')
if not passwd:
raise APIValueError('passwd', 'Invalid password.')
users = yield from User.findAll('email=?', [email])
if len(users) == 0:
raise APIValueError('email', 'Email not exist.')
user = users[0]
# check passwd:
sha1 = hashlib.sha1()
sha1.update(user.id.encode('utf-8'))
sha1.update(b':')
sha1.update(passwd.encode('utf-8'))
if user.passwd != sha1.hexdigest():
raise APIValueError('passwd', 'Invalid password.')
# authenticate ok, set cookie:
r = web.Response()
r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
user.passwd = '******'
r.content_type = 'application/json'
r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
return r
示例7: api_get_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def api_get_users():
users = yield from User.findAll(orderBy='create_at desc')
for u in users:
u.password = '******'
return dict(users)
示例8: get_api_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def get_api_users(request):
users = yield from User.findAll(orderBy='created_at desc')
for u in users:
u.passwd = '*******'
return dict(users=users)
示例9: api_get_users
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def api_get_users(request):
users = yield from User.findAll(orderBy='created_at desc')
logging.info('users = %s and type = %s' % (users, type(users)))
for u in users:
u.passwd = '******'
return dict(users=users)
示例10: test_findAll
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import findAll [as 别名]
def test_findAll(loop):
yield from create_pool(loop,**kw)
users = yield from User.findAll("name = 'aaa'",**{'limit':(0,5)})
print(users)