本文整理汇总了Python中database.DatabaseManager.create_user方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.create_user方法的具体用法?Python DatabaseManager.create_user怎么用?Python DatabaseManager.create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.create_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import create_user [as 别名]
def register():
db_manager = DatabaseManager()
username = request.json.get('username')
password = sha512_crypt.encrypt(request.json.get('password'), salt=app.config['SECURITY_PASSWORD_SALT'], rounds=5000)
email = request.json.get('email')
# Check if everything filled in
if username is None or password is None or email is None:
return abort(400) # missing arguments
# Check if already exists
elif db_manager.username_exists(username) or db_manager.email_exists(email):
# username and/or email do already exist
return response_cache_header("ERROR, username and/or email do already exist", cache_control="no-cache")
else:
db_manager.create_user(username=username, password_hash=password, email=email, email_verified=False)
# Email verification
token = generate_confirmation_token(email)
confirm_url = url_for('verify_email', token=token, _external=True)
html = render_template('email.html', confirm_url=confirm_url)
subject = "Please confirm your email"
send_email(email, subject, html)
return response_cache_header("Successfully created user, please verify email.\n", cache_control="no-cache")
示例2: register
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import create_user [as 别名]
def register():
db_manager = DatabaseManager()
username = request.json.get("username")
password = sha512_crypt.encrypt(
request.json.get("password"), salt=app.config["SECURITY_PASSWORD_SALT"], rounds=5000
)
email = request.json.get("email")
email = email.lower()
if not validate_email(email):
return response_cache_header(
json.dumps({"response": "Not a valid email address", "success": False}), cache_control="no-cache"
)
# Check if everything filled in
elif username is None or password is None or email is None:
return abort(400) # missing arguments
# Check if already exists
elif db_manager.username_exists(username) or db_manager.email_exists(email):
# username and/or email do already exist
return response_cache_header(
json.dumps({"response": "ERROR, username and/or email already exist", "success": False}),
cache_control="no-cache",
)
else:
db_manager.create_user(username=username, password_hash=password, email=email, email_verified=False)
# Email verification
token = generate_confirmation_token(email)
confirm_url = "https://api.woording.com/verify/" + token
html = render_template("email.html", confirm_url=confirm_url)
subject = "Please confirm your email"
send_email(email, subject, html)
return response_cache_header(
json.dumps({"response": "Succesfully created user, please verify email.", "success": True}),
cache_control="no-cache",
)