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


Python User.find_first方法代码示例

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


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

示例1: test

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def test():
    u = User(name='Test', 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
开发者ID:jy00464346,项目名称:mytest-python-webapp,代码行数:16,代码来源:test_db.py

示例2: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.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 _RE_EMAIL.match(email):
        raise APIValueError("email")
    if not password or not _RE_MD5.match(password):
        raise APIValueError("password")
    user = User.find_first("where email=?", email)
    if user:
        raise APIError("register:failed", "email", "Email is already in use.")
    user = User(
        name=name,
        email=email,
        password=password,
        image="http://www.gravatar.com/avatar/%s?d=mm&s=120" % hashlib.md5(email).hexdigest(),
    )
    user.insert()

    # make session cookie:
    cookie = make_signed_cookie(user.id, user.password, None)
    ctx.response.set_cookie(_COOKIE_NAME, cookie)
    return user
开发者ID:skyoskiyqq,项目名称:JnswWebApp,代码行数:28,代码来源:urls.py

示例3: get_code

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def get_code():
    i = ctx.request.input(num='')
    num = i.num.strip()
    if not num or not _RE_PHONE.match(num):
        raise APIError('TooOften',num,'the phone num is not right!','-1')
    user = User.find_first('where phone=?', num)
    if user and user.valid==True:
        raise APIError('duplicated:phone','phone','phone is already in use.','-1')
    verify_code = VerifyCode.find_first('where num=?',num)
    if verify_code:
        update_time = verify_code.created_at
        logging.info('the update_time %d %d' % (update_time, time.time()))
        delta = 60 - (time.time() - update_time) 
        if delta > 0:
            raise APIError('TooOften:code','%d' %  delta,'get code too often','-1')
        verify_code.code = next_code();
        verify_code.created_at = time.time()
        verify_code.update()
    else:
        verify_code = VerifyCode(num=num,code=next_code())
        verify_code.insert()
    verify_code.pop('id')
    verify_code.pop('created_at')
    verify_code.errcode='0'
    return verify_code
开发者ID:saltdealer,项目名称:space,代码行数:27,代码来源:urls.py

示例4: feed

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def feed():
    blogs = Blogs.find_by('order by created desc limit ?', 10)
    for blog in blogs:
        if blog.tags:
            blog.xtags = blog.tags.split(',')
    url = configs.get('blog_url')
    user = User.find_first('')
    ctx.response.content_type = 'application/xml'
    return dict(blogs=blogs, url=url, user=user)
开发者ID:zhu327,项目名称:blog,代码行数:11,代码来源:urls.py

示例5: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def authenticate():
    i = ctx.request.input()
    email = i.get('email').strip().lower()
    password = i.get('password')
    user = User.find_first('where email=?', email)
    if not user:
        raise APIError('auth:failed', 'email', 'Invalid email')
    elif user.password != password:
        raise APIError('auth:failed', 'password', 'Invalid password')
    max_age = 604800
    cookie = make_signed_cookie(user.id, user.password, max_age)
    ctx.response.set_cookie(_COOKIE_NAME, cookie, max_age=max_age)
    user.password = '******'
    return user
开发者ID:zhu327,项目名称:blog,代码行数:16,代码来源:urls.py

示例6: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def authenticate():
    i = ctx.request.input(remember='')
    email = i.email.strip().lower()
    password = i.password
    remember = i.remember
    user = User.find_first('where email=?', email)
    if user is None:
        raise APIError('auth:failed', 'email', 'Invalid email.')
    elif user.password != password:
        raise APIError('auth:failed', 'password', 'Invalid password.')
    max_age = 604800 if remember=='true' else None
    cookie = make_signed_cookie(user.id, user.password, max_age)
    ctx.response.set_cookie(_COOKIE_NAME, cookie, max_age=max_age)
    user.password = '******'
    return user
开发者ID:zathing,项目名称:awesome-python-webapp,代码行数:17,代码来源:urls.py

示例7: parse_signed_cookie

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def parse_signed_cookie(cookie_str):
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        user_id, expires, md5 = L
        if int(expires) < time.time():
            return None
        user = User.find_first('where user_id=?', user_id)
        if user is None:
            return None
        if md5 != hashlib.md5('%s-%s-%s-%s' % (user_id, user.user_key, expires, _COOKIE_KEY)).hexdigest():
            return None
        return user
    except:
        return None
开发者ID:Spacebody,项目名称:ProfStudSystem,代码行数:18,代码来源:urls.py

示例8: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def authenticate():
    i = ctx.request.input(remember='')
    user_id = i.re_id.strip()
    user_key = i.re_key
    remember = i.remember
    user = User.find_first('where user_id=?', user_id)
    if user is None:
        raise APIError('auth:failed', 'ID', 'Invalid email.')
    elif user.user_key != user_key:
        raise APIError('auth:failed', 'password', 'Invalid password.')
    # make session cookie:
    max_age = 604800 if remember=='true' else None
    cookie = make_signed_cookie(str(user.user_id), user.user_key, max_age)
    ctx.response.set_cookie(_COOKIE_NAME, cookie, max_age=max_age)
    user.user_key = '******'
    return user
开发者ID:Spacebody,项目名称:ProfStudSystem,代码行数:18,代码来源:urls.py

示例9: authenticate

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def authenticate():
    i = ctx.request.input(remember="")
    email = i.email.strip().lower()
    password = i.password
    remember = i.remember
    user = User.find_first("where email=?", email)
    if user is None:
        raise APIError("auth:failed", "email", "Invalid email.")
    elif user.password != password:
        raise APIError("auth:failed", "password", "Invalid password.")
    # make session cookie:
    max_age = 604800 if remember == "true" else None
    cookie = make_signed_cookie(user.id, user.password, max_age)
    ctx.response.set_cookie(_COOKIE_NAME, cookie, max_age=max_age)
    user.password = "******"
    return user
开发者ID:skyoskiyqq,项目名称:JnswWebApp,代码行数:18,代码来源:urls.py

示例10: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def create_user():
    i = ctx.request.input(phone='',password='',code='')
    phone = i.phone.strip()
    password = i.password.strip()
    code = i.code.strip()
    verify = VerifyCode.find_first('where num=?', phone)
    logging.info('the code %s and verify %s' %(code,verify))
    if not verify or verify.code!=code:
        raise APIError('register:failed','verify code','verify code is not correct.','-1')
    if time.time() - verify.created_at > 90:
        raise APIValueError('code',errcode='-3')
    
    if not phone or not _RE_PHONE.match(phone):
        raise APIValueError('phone',errcode='-1')
    if not password:
        raise APIValueError('password', errcode='-1')

    verify.delete()
    user = User.find_first('where phone=?',phone)
    if user and user.valid==True:
        raise APIError('register:failed','phone','phone is already in use.')

    if user:
        token = Token.find_first('where id=?', user.id)
        if not token:
            token_string = next_id()
            token = Token(id = user.id, token1=token_string, token2 = token_string)
            token.insert()
        else:
            token.token1 = next_id()
            logging.info('the update token is %s' % token.token1)
            token.update()
        user.password = password
        user.update()
        user.token = token.token1
    else:
        user = User(phone=phone, valid=False, password=password)
        user.insert()
        token_string = next_id()
        token = Token(id = user.id, token1=token_string, token2 = token_string)
        token.insert()
        user.token = token.token1
    user.pop('id')
    user.pop('password')
    user.pop('created_at')
    user.errcode='0'
    return user
开发者ID:saltdealer,项目名称:space,代码行数:49,代码来源:urls.py

示例11: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def register_user():
	i = ctx.request.input(name = '', email = '', password = '')
	name = i.name.strip()
	email = i.email.strip.lower()
	password = i.password
	if not name:
		raise APIValueError('name')
	if not email or not _RE_EMAIL.match(email):
		raise APIValueError('email')
	if not password or not _RE_MD5.match(password):
		raise APIValueError('password')
	user = User.find_first('where email = ?', email)
	if user:
		raise APIError('register:failed', 'email', 'Email has already exist')
	user = User(name = name, email = email, password = password, image = "http://www.gravatar.com/avatar/%s?d=mm&s=120" %hashlib.md5(email).hexdigest())
	user.insert()
	return user
开发者ID:lgknight,项目名称:awesome-python-webapp,代码行数:19,代码来源:urls.py

示例12: user_interceptor

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def user_interceptor(next):
    logging.info('try to bind user from token')
    i = ctx.request.input(token='',phone='')
    token = i.token.strip()
    phone = i.phone.strip()
    logging.info('the token %s and phone %s'% (token,phone))
    ctx.request.user = None
    if not phone or not _RE_PHONE.match(phone):
        return next()
    user = User.find_first('where phone=?',phone)
    if not user:
        return next()
    token_verify = Token.find_first('where id=?',user.id)
    if token_verify.token1 != token:
        return next()
    logging.info('the token is %s' % token_verify)
    ctx.request.user = user
    return next()
开发者ID:saltdealer,项目名称:space,代码行数:20,代码来源:urls.py

示例13: findAllPeople

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def findAllPeople(types, i, times, html, sname):
    followees = html.find_all('div', class_='zm-profile-section-item')
    l = {'nowSpaceName': sname, 'spaceName':''}
    for people in followees:
        linker = people.find('a', class_='zm-item-link-avatar')
        space_match = space_pattern.match(linker['href'])
        if space_match:
            space_name = space_match.group(1)
            ul = UserList.get(space_name)
            u = User.find_first('where spaceName=?', space_name)
            if u is None and ul is None:
                l['spaceName'] = space_name
                d = newSpaceName(l)
                if check:
                    print types, i, times, space_name, d
            else:
                if check:
                    print types, i, times, space_name, "exist."
开发者ID:lmzqwer2,项目名称:zhihu_spider,代码行数:20,代码来源:spider.py

示例14: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def register_user():
    check_admin()
    i = ctx.request.input(name='', email='', password='')
    name = i['name'].strip()
    email = i['email'].strip().lower()
    password = i['password'].strip()
    if not name:
        raise APIValueError(name)
    if not email and not _RE_EMAIL.match(email):
        raise APIValueError(email)
    if not password and not _RE_MD5.match(password):
        raise APIValueError(password)
    user = User.find_first('')
    user.name = name
    user.email=email
    user.password=password
    user.update()
    user.password = '******'
    return user
开发者ID:zhu327,项目名称:blog,代码行数:21,代码来源:urls.py

示例15: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import find_first [as 别名]
def register_user():
	i = ctx.request.input(name='', email='', password='')
	name = i.name.strip()
	email = i.email.strip().lower()
	password = i.password
	if not name:
		raise APIValueError('name')
	if not email or not _RE_EMAIL.match(email):
		raise APIValueError('email')
	if not password or not _RE_MD5.match(password):
		raise APIValueError('password')
	user = User.find_first('where email=?', email)
	if user:
		raise APIError('register:failed', 'email', 'Email is already in use.')
	user = User(name=name, email=email, password=password, image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email).hexdigest())
	user.insert()
	# make session cookie
	cookie = make_signed_cookie(user.id, user.password, None)
	ctx.response.set_cookie(_COOKIE_NAME, cookie)
	return user
开发者ID:dasbindus,项目名称:my-python-webapp,代码行数:22,代码来源:urls.py


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