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


Python User.insert方法代码示例

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


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

示例1: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [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

示例2: signup

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
def signup(form):
    user = User(form.username.data, form.email.data, form.password.data)

    try:
        user.insert()
    except Exception as e:
        print(e)
        return False
    login_user(user)

    return True
开发者ID:sctlee,项目名称:flask-docker,代码行数:13,代码来源:auth.py

示例3: test

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [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

示例4: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [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

示例5: register

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
def register():
    """ Registers a new user. """
    username = request.args.get('username')
    email = request.args.get('email')
    password = request.args.get('password')

    if not all([username, email, password]):
        msg = 'You must provide a username, email, and password to register.'
        return jsonify(success=False, message=msg)

    existing_accounts = db.session.query(User)\
                                  .filter(or_(User.username == username,
                                              User.email == email)).all()

    if existing_accounts:
        usernames = [u.username for u in existing_accounts]

        msg = 'There is already an account with this '
        if username in usernames:
            msg += 'username'
        else:
            msg += 'email address'
        return jsonify(success=False, message=msg)

    new_user = User(username=username, email=email, active=False,
                    password=sha256_crypt.encrypt(password))

    new_user.insert()

    site_url = CONFIG.get('app', 'url')

    verify_link = '{0}/verify?id={1}'.format(site_url, new_user.id)

    subject = "Welcome to {0}!".format(CONFIG.get('app', 'name'))

    email_msg = '\n'.join([
        'Welcome! Your account has been created!',
        'Please click the link below to verify your email address.',
        verify_link, '', '',
        'Thank you for joining. We hope you enjoy your account.'
    ])

    send_mail(new_user.email, subject, email_msg)

    return jsonify(success=True,
                   message='Please check your email to verify your account.')
开发者ID:Dwooll94,项目名称:facial-signin,代码行数:48,代码来源:application.py

示例6: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [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

示例7: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [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

示例8: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
def register_user():
    i = ctx.request.input(user_name='', user_id='', user_key='')
    re_name = i.user_name.strip()
    re_id = i.user_id.strip()
    re_key = i.user_key
    if not re_name:
        raise APIValueError('name')
    if not re_id or not _RE_ID.match(re_id):
        raise APIValueError('id')
    if not re_key or not _RE_MD5.match(re_key):
        raise APIValueError('password')
    user = User.find_first('where user_id=?', re_id)
    if user:
        raise APIError('register:failed', 'id', 'ID is already in use.')
    user = User(user_id=re_id, user_type=1, user_key=re_key)
    user.insert()
    # make session cookie:
    cookie = make_signed_cookie(str(user.user_id), user.user_key, None)
    ctx.response.set_cookie(_COOKIE_NAME, cookie)
    return user
开发者ID:Spacebody,项目名称:ProfStudSystem,代码行数:22,代码来源:urls.py

示例9: register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [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', '该邮箱已被使用.')
    user = User(name=name, email=email, password=password, image='http://7mnmgy.com1.z0.glb.clouddn.com/myblog.jpg')
    user.insert()
    # make session cookie:
    cookie = make_signed_cookie(user.id, user.password, None)
    ctx.response.set_cookie(_COOKIE_NAME, cookie)
    return user
开发者ID:akicqi,项目名称:python_mini_blog,代码行数:22,代码来源:urls.py

示例10: asking

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
def asking(request, **kwargs):
    try:
        u_fname = request.form['fname']
        u_lname = request.form['lname']
        u_username = request.form['username']
        u_email = request.form['email']
        u_password = request.form['pass']
        u_confirm_password = request.form['confirm-pass']
        u_location = request.form['location']
        u_day = request.form['dob-day']
        u_month = request.form['dob-month']
        u_year = request.form['dob-year']
        u_about_me = request.form['question-body']
        u_avatar_url = request.form['profile-pic']
    except KeyError:
        return questions(request)

    if request.form['pass'] != request.form['confirm-pass']:
        return register(request)
    u = User()
    u.first_name = request.form['fname']
    u.last_name = request.form['lname']
    u.name = request.form['username']
    u.email = request.form['email']
    u.password = request.form['pass']
    u.area = request.form['location']
    #u.day = request.form['dob-day']
    #u.month = request.form['dob-month']
    #u.year = request.form['dob-year']
    u.age = 18
    u.about = request.form['question-body']
    u.avatar = request.form['profile-pic']

    u.insert()
    print "the new uid is %s" % u.id
    user_login(u.id)
    return questions(request)
开发者ID:lachlanmarks,项目名称:meno,代码行数:39,代码来源:views.py

示例11: update_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
def update_user(sender, response, access_token):
    # Has this account been connected before?
    uid = auth.APIS[session['realm']].get_uid(response, oauth_token = access_token)
    uid_obj = UID.find_one(
        {'uid': uid, 'datastream': session['realm']}, as_obj = True)
    
    if not uid_obj:
        if not current_user.is_authenticated():
            user = User()
            user.insert()
        else:
            user = current_user
            
        uid_obj = UID(uid = uid,
                      datastream = session['realm'],
                      user_id = user['_id'])
        uid_obj.insert()
    
    else:
        user = User.find_one({'_id':uid_obj['user_id']}, as_obj = True)
        
    if not 'external_tokens' in user or not isinstance(user['external_tokens'], dict):
        user['external_tokens'] = {}
        
    if not 'refresh_tokens' in user:
        user['refresh_tokens'] = {}
    
    if 'refresh_token' in response.content:
        user['refresh_tokens'][session['realm']] = response.content['refresh_token']
        
    user['external_tokens'][session['realm']] = access_token
    
    if not current_user.is_authenticated():
        login_user(user)
    
    user.save()
开发者ID:ryepdx,项目名称:bittrails_platform,代码行数:38,代码来源:signals.py

示例12: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
 def post(self):
     data = self.request.data(username='', password='', repassword='', email='')
     username = data.username
     password = data.password
     repassword = data.repassword
     email = data.email.strip().lower()
     if not username:
         self.redirect('/signin')
     if not password:
         self.redirect('/signin')
     if not repassword:
         self.redirect('/signin')
     if not data.email:
         self.redirect('/signin')
     if password != repassword:
         self.redirect('/signin')
     if User.select_one('name=?', username):
         self.redirect('/signin')
     if User.select_one('email=?', email):
         self.redirect('/signin')
     user = User(name=username, password=encrpt_password(password), \
             email=email)
     user.insert()
     self.redirect('/login')
开发者ID:damnever,项目名称:LTsite,代码行数:26,代码来源:urls.py

示例13: api_register_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
def api_register_user(*, email, name, passwd):
    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.find_all('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.insert()
    # 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:povs2012,项目名称:awesome-webapp-python3,代码行数:24,代码来源:handlers.py

示例14: User

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
#!/usr/bin/env python
# encoding:utf-8
__author__ = 'YJX'
__data__ = 2016 / 6 / 17

from models import User, Blog, Comment
from transwarp import db

if __name__ == '__main__':
    db.create_engine(user='root', password='123456', database='awesome')
    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:love123i,项目名称:awesome-python-webapp,代码行数:23,代码来源:test_db.py

示例15: test_insert

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import insert [as 别名]
 def test_insert(self):
     query = User.insert(name='jack', email='[email protected]')
     assert query.execute() == 1
     assert User.count() == 1
     user = User.getone()
     assert user.name == 'jack' and user.email == '[email protected]'
开发者ID:bopo,项目名称:skylark,代码行数:8,代码来源:tests.py


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