本文整理汇总了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'))
示例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))
示例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)