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


Python DatabaseManager.email_exists方法代码示例

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


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

示例1: register

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import email_exists [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")
开发者ID:codevbus,项目名称:woording-api,代码行数:29,代码来源:api.py

示例2: register

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import email_exists [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",
        )
开发者ID:woording,项目名称:woording-api,代码行数:44,代码来源:api.py


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