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


Python User.create方法代码示例

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


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

示例1: join

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import create [as 别名]
def join():
	if request.method == 'GET':
		return render_template('join.html')
	username = request.form.get('username')
	password = request.form.get('password')
	email = request.form.get('email')
	if not username:
		flash('Please input username')
            	return redirect(url_for('join'))
	elif not password:
		flash('Please input password')
            	return redirect(url_for('join'))
	elif not email:
		flash('Please input email')
            	return redirect(url_for('join'))
        try:
         	# use the .get() method to quickly see if a user with that name exists
           	user = User.get(username=username)
            	flash('That username is already taken')
	except User.DoesNotExist:
           	# if not, create the user and store the form data on the new model
            	user = User.create(username=username,
			password=md5(password).hexdigest(),	
			email=email,join_date=datetime.datetime.now())
            		# mark the user as being 'authenticated' by setting the session vars
           	auth_user(user)
            	return redirect(url_for('homepage'))
开发者ID:justasabc,项目名称:python_tutorials,代码行数:29,代码来源:app.py

示例2: provision

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import create [as 别名]
def provision(key):
    try:
        key = ProvisioningKey.get(ProvisioningKey.key == key)
    except DoesNotExist:
        abort(404)

    if request.method == 'GET':
        api_key = str(hexlify(urandom(16)), 'utf8').upper()
        return render_template('provision.html', api_key=api_key)
    elif request.method == 'POST':
        if 'username' not in request.form or 'api_key' not in request.form:
            return jsonify(**{'error': 'missing required form field'})

        try:
            user = User.create(username=request.form['username'],
                               api_key=request.form['api_key'])
            key.delete_instance()
        except IntegrityError:
            return jsonify(**{'error': 'duplicate username or API key'})

        return redirect(
            url_for('frontend.provision_sharex', api_key=user.api_key))
开发者ID:nolanlum,项目名称:pshuu,代码行数:24,代码来源:frontend.py

示例3: create_user

# 需要导入模块: from db import User [as 别名]
# 或者: from db.User import create [as 别名]
def create_user(user_id, social_id):
    return User.create(social_id=social_id, username=user_id, role='user', is_active=True)
开发者ID:odonnellryan,项目名称:Bulletin,代码行数:4,代码来源:db_mods.py


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