当前位置: 首页>>代码示例>>Python>>正文


Python User.findAll方法代码示例

本文整理汇总了Python中models.User.findAll方法的典型用法代码示例。如果您正苦于以下问题:Python User.findAll方法的具体用法?Python User.findAll怎么用?Python User.findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.findAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def api_register_user(*, email, name, passwd,img_uuid):
    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:
        raise APIValueError('email', 'Email is already in use.')
    users = yield from User.findAll('name=?', [name])
    if len(users) > 0:
        raise APIValueError('name', 'name is already in use.')
    uid = next_id()
    sha1_passwd = '%s:%s' % (uid, passwd)
    img_path="/static/HeadImg/"
    img_path=img_path+img_uuid
    img_path=img_path+".jpg"

    path=os.path.abspath('.')
    path=os.path.join(path,"static")
    path=os.path.join(path,"HeadImg")
    path=os.path.join(path,"%s.jpg" % img_uuid)
    if not os.path.exists(path):
        img_path="/static/img/default.jpg"
    user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image=img_path)
    yield from user.save()
    # make session 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
开发者ID:daihaovigg,项目名称:web,代码行数:36,代码来源:handlers.py

示例2: test

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def test(request):
    logging.info('findAll, /test')
    users = yield from User.findAll()
    return {
        '__template__': 'test.html',
        'users': users
    }
开发者ID:tuouo,项目名称:PythonWeb,代码行数:9,代码来源:handlers.py

示例3: run

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def run():
    yield from orm.create_pool(host='127.0.0.1', port=3306,
                                           user='root', password='root',
                                           db='awesome', loop=loop)

    users_table = yield from User.findAll()
    print(users_table)
开发者ID:macwu1992,项目名称:awesome-python3-webapp,代码行数:9,代码来源:db_run.py

示例4: test_remove

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def test_remove(loop):
    yield from orm.create_pool(user='www-data', password='www-data', database='awesome',loop=loop)
    users = yield from User.findAll(where='email=?', args=('[email protected]',))
    for u in users:
        if isinstance(u, orm.Model):
            # 一定要注意加上yield from
            yield from u.remove()
开发者ID:kitianFresh,项目名称:awesome-python3-webapp,代码行数:9,代码来源:test.py

示例5: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def authenticate(*, email, passwd):
    # 如果email或passwd为空
    if not email:
        raise APIValueError('email', 'Invalid email.')
    if not passwd:
        raise APIValueError('passwd', 'Invalid password.')
    # 根据email在库里查找匹配的用户
    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':')
    # 在Python 3.x版本中,把'xxx'和u'xxx'统一成Unicode编码,即写不写前缀u都是一样的,
    # 而以字节形式表示的字符串则必须加上b前缀:b'xxx'
    sha1.update(passwd.encode('utf-8'))
    '''browser_sha1_passwd = '%s:%s' % (user.id, passwd)
    browser_sha1 = hashlib.sha1(browser_sha1_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
开发者ID:COREENE,项目名称:python,代码行数:33,代码来源:handlers.py

示例6: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.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()
    passwd_sha1=email + ":" + passwd
    sha1.update(passwd_sha1.encode('utf-8'))
    # sha1.update(user.email.encode('utf-8'))
    # sha1.update(b':')
    # sha1.update(passwd.encode('utf-8'))
    if user.passwd != sha1.hexdigest():
        raise APIValueError('passwd', sha1.hexdigest()+'<br />'+user.passwd)
    # authenticate ok, set cookie:
    # referer = request.headers.get('Referer')
    r = web.HTTPFound('/dashboard/i')
    # 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
开发者ID:lokiiart,项目名称:51upali,代码行数:29,代码来源:handlers.py

示例7: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.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]) # 在数据库中查找email,将以list形式返回
    if len(users) == 0: # 查询结果为空,即数据库中没有相应的email记录,说明用户不存在
        raise APIValueError("email", "Email not exits")
    user = users[0] # 取得用户记录.事实上,就只有一条用户记录,只不过返回的是list
    # 验证密码
    # 数据库中存储的并非原始的用户密码,而是加密的字符串
    # 我们对此时用户输入的密码做相同的加密操作,将结果与数据库中储存的密码比较,来验证密码的正确性
    # 以下步骤合成为一步就是:sha1 = hashlib.sha1((user.id+":"+passwd).encode("utf-8"))
    # 对照用户时对原始密码的操作(见api_register_user),操作完全一样
    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")
    # 用户登录之后,同样的设置一个cookie,与注册用户部分的代码完全一样
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 600), max_age=600, httponly=True)
    # r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    # r.set_cookie(COOKIE_NAME, user2cookie(user, 600), max_age=600, httponly=True)
    user.passwd = "*****"
    r.content_type = "application/json"
    r.body = json.dumps(user, ensure_ascii=False).encode("utf-8")
    return r
开发者ID:Joe-Blake,项目名称:Blog,代码行数:32,代码来源:handlers.py

示例8: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def authenticate(*, email, passwd):
	# 如果email或passwd为空,都说明有错误
	if not email:
		raise APIValueError('email', 'Invalid email')
	if not passwd:
		raise APIValueError('passwd', 'Invalid  passwd')
	# 根据email在库里查找匹配的用户
	users = yield from User.findAll('email=?', [email])
	# 没找到用户,返回用户不存在
	if len(users) == 0:
		raise APIValueError('email', 'email not exist')
	# 取第一个查到用户,理论上就一个
	user = users[0]
	# 按存储密码的方式获取出请求传入的密码字段的sha1值
	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()
	# 添加cookie
	r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
	# 只把要返回的实例的密码改成'******',库里的密码依然是正确的,以保证真实的密码不会因返回而暴漏
	user.passwd = '******'
	# 返回的是json数据,所以设置content-type为json的
	r.content_type = 'application/json'
	# 把对象转换成json格式返回
	r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
	return r
开发者ID:Eliefly,项目名称:eliefly-blog,代码行数:34,代码来源:handlers.py

示例9: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def api_register_user(*, email, name, passwd):
    #判断name是否为空:
    if not name or not name.strip():
        raise APIValueError('name')
    #判断email是否为空及是否满足email格式:
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    #判断password首付为空及是否满足password格式:
    if not passwd or not _RE_SHA1.match(passwd):
        raise APIValueError('passwd')
    #数据中查询对应的email信息:
    users = yield from User.findAll('email=?', [email])
    #判断查询结果是否存在,若存在则返回异常提示邮件已存在:
    if len(users) > 0:
        raise APIError('register:failed', 'email', 'Email is already in use.')
    #生成唯一ID:
    uid = next_id()
    #重构唯一ID和password成新的字符串:
    sha1_passwd = '%s:%s' % (uid, passwd)
    #构建用户对象信息:
    #hashlib.sha1().hexdigest():取得SHA1哈希摘要算法的摘要值。
    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:
    #构造session cookie信息:
    r = web.Response()
    #aiohttp.web.StreamResponse().set_cookie():设置cookie的方法。
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)   #max_age:定义cookie的有效期(秒);
    user.passwd = '******'
    r.content_type = 'application/json'
    #以json格式序列化响应信息; ensure_ascii默认为True,非ASCII字符也进行转义。如果为False,这些字符将保持原样。
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r
开发者ID:zhangshengyue,项目名称:text,代码行数:36,代码来源:handlersdetail.py

示例10: show_all_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def show_all_user(request):
    users = yield from User.findAll()
    logging.info('index ...')
    return {
        '__template__': 'test.html',
        'users': users
    }
开发者ID:crazyAxe,项目名称:aWebapp,代码行数:9,代码来源:handlers.py

示例11: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def api_register_user(*, email, name, password):
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not password or not _RE_SHA1.match(password):
        raise APIValueError('password')
    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, password)
    admin = False
    if email == '[email protected]':
        admin = True

    user = User(id=uid, name=name.strip(), password=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(),
                admin=admin)
    yield from user.save()
    logging.info('save user ok.')
    # 构建返回信息
    r = web.Response()
    r.set_cookie(_COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    # 把要返回的实例的密码改成‘******’,这样数据库中的密码是正确的,并保证真实的密码不会因返回而泄露
    user.password = '******'
    r.content_type = 'application/json;charset:utf-8'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r
开发者ID:crazyAxe,项目名称:aWebapp,代码行数:31,代码来源:handlers.py

示例12: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def api_register_user(*, email, name, passwd):
    if not name or not name.strip():
        raise APIValueError('name', 'Invalid name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email', 'Invalid email')
    if not passwd or not _RE_SHA1.match(passwd):
        raise APIValueError('passwd', 'Invalid password')

    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, email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(),
                image='http://s.gravatar.com/avatar/%s?s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
    yield from user.save()

    #make session 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
开发者ID:ianzhengnan,项目名称:blog-python3,代码行数:27,代码来源:handlers.py

示例13: api_get_users

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def api_get_users(request):
    # 返回所有的用户信息jason格式
    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)
开发者ID:JasonZhao001,项目名称:awesome-python3-webapp,代码行数:9,代码来源:handlers.py

示例14: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.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])
	# 根据email在库里查找匹配的用户
	if not len(users):
		raise APIValueError('email', 'email not exist')
	user = users[0]

	browser_sha1_passwd = '%s:%s' % (user.id, passwd)
	browser_sha1 = hashlib.sha1(browser_sha1_passwd.encode('utf-8'))
	'''sha1 = hashlib.sha1()
	sha1.update(user.id.encode('utf-8'))
	sha1.update(b':')
	# 在Python 3.x版本中,把'xxx'和u'xxx'统一成Unicode编码,即写不写前缀u都是一样的,而以字节形式表示的字符串则必须加上b前缀:b'xxx'。
	sha1.update(passwd.encode('utf-8'))'''
	if user.passwd != browser_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, default = lambda o:o.__dict__).encode('utf-8')
	return r    
开发者ID:JasonZhao001,项目名称:awesome-python3-webapp,代码行数:31,代码来源:handlers.py

示例15: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import findAll [as 别名]
def authenticate(*, email, passwd):
    # 验证邮箱与密码的合法性
    if not email:
        raise APIValueError('email', 'Invalid email.')
    if not passwd:
        raise APIValueError('passwd', 'Invalid passwd.')
    users = yield from User.findAll('email=?', [email])
    if len(users) == 0:
        raise APIValueError('email', 'Email not exists.')
    user = users[0] # 获得用户记录,返回的记录是list
    # 验证密码
    # 数据库中存储的并非原始的用户密码,而是加密的字符串
    # 我们对此时用户输入的密码做相同的加密操作,将结果与数据库中储存的密码比较,来验证密码的正确性
    # 以下步骤合成为一步就是:sha1 = hashlib.sha1((user.id+":"+passwd).encode("utf-8"))
    # 对照用户时对原始密码的操作(见api_register_user),操作完全一样
    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.')
    # 用户登录之后,同样的设置一个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
开发者ID:Patrickctyyx,项目名称:superawesome-python3-webapp,代码行数:30,代码来源:handlers.py


注:本文中的models.User.findAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。