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


Python DatabaseManager.username_exists方法代码示例

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


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

示例1: register

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_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: get

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_exists [as 别名]
def get(username):
	db_manager = DatabaseManager()

	token = request.json.get('token')
	if token is None or token is "":
		return abort(401)
	
	# Verifiy token
	token_credentials = db_manager.verify_auth_token(token=token)
	if token_credentials is None:
		return abort(401)
	elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
		return abort(401)
	
	if db_manager.username_exists(username):
		# Return all lists
		if token_credentials[0] == username:
			user_info = db_manager.get_user(username)
			list_lists = db_manager.get_lists_for_user(username)
			for l in list_lists: del l['user_id']; del l['id']

			return response_cache_header(json.dumps({
				'username': user_info.get("username"),
				'email' : user_info.get("email"),
				'lists' : list_lists
				}))
		# Return friend lists if you are friends
		elif db_manager.users_are_friends(username, token_credentials[0]):
			user_info = db_manager.get_user(username)
			list_lists = db_manager.get_lists_for_user(username)
			
			for l in list_lists[:]:  # Make a slice copy of the entire list
				if l['shared_with'] == "0":
					list_lists.remove(l)
				del l['user_id']
				del l['id']

			return response_cache_header(json.dumps({
				'username': user_info.get("username"),
				'email' : user_info.get("email"),
				'lists' : list_lists
				}))
		# Return everyone shared lists
		else:
			user_info = db_manager.get_user(username)
			list_lists = db_manager.get_lists_for_user(username)
			for l in list_lists[:]:  # Make a slice copy of the entire list
				if l['shared_with'] != "2":
					list_lists.remove(l)
				del l['user_id']
				del l['id']

			return response_cache_header(json.dumps({
				'username': user_info.get("username"),
				'email' : user_info.get("email"),
				'lists' : list_lists
				}))

	else:
		return response_cache_header(json.dumps({"error":"User not found"}), cache_control="no-cache")
开发者ID:codevbus,项目名称:woording-api,代码行数:62,代码来源:api.py

示例3: show_user_list

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_exists [as 别名]
def show_user_list(username, listname):
	db_manager = DatabaseManager()

	token = request.json.get("token")
	if token is None or token is "":
		return json.dumps({ 'username':'ERROR, No token' })
	
	# Verifiy token
	token_credentials = db_manager.verify_auth_token(token=token)
	if token_credentials is None:
		return json.dumps({ 'username':'ERROR, No user' })
	elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
		return json.dumps({ 'username':'ERROR, Wrong token'})

	if db_manager.username_exists(username):
		if db_manager.listname_exists_for_user(username, listname):
			list_data = db_manager.get_list(username, listname)
			shared_with = list_data.get("shared_with")
			translations = db_manager.get_translations_for_list(username, listname)
			for translation in translations: del translation['id']; del translation['list_id']
			
			# Check if is owner
			if username == token_credentials[0]:
				return json.dumps({
					'listname' : listname,
					'language_1_tag' : list_data.get("language_1_tag"),
					'language_2_tag' : list_data.get("language_2_tag"),
					'words' : translations,
					'shared_with' : shared_with
				})
			# Check if is friend
			elif shared_with == '1' and db_manager.users_are_friends(username, token_credentials[0]):
				return json.dumps({
					'listname' : listname,
					'language_1_tag' : list_data.get("language_1_tag"),
					'language_2_tag' : list_data.get("language_2_tag"),
					'words' : translations,
					'shared_with' : shared_with
				})
			elif shared_with == '2':
				return json.dumps({
					'listname' : listname,
					'language_1_tag' : list_data.get("language_1_tag"),
					'language_2_tag' : list_data.get("language_2_tag"),
					'words' : translations,
					'shared_with' : shared_with
				})
			else:
				abort(401)

		else:
			return json.dumps({
				'username': 'ERROR: This shouldn\'t happen'
				})
	else:
		return json.dumps({
			'username': 'ERROR: This shouldn\'t happen'
			})
开发者ID:Heasummn,项目名称:woording-api,代码行数:60,代码来源:api.py

示例4: show_user_list

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_exists [as 别名]
def show_user_list(username, listname):
	db_manager = DatabaseManager()

	token = request.json.get("token")
	if token is None or token is "":
		return abort(401)
	
	# Verifiy token
	token_credentials = db_manager.verify_auth_token(token=token)
	if token_credentials is None:
		return abort(401)
	elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
		return abort(401)

	if db_manager.username_exists(username):
		if db_manager.listname_exists_for_user(username, listname):
			list_data = db_manager.get_list(username, listname)
			shared_with = list_data.get("shared_with")
			translations = db_manager.get_translations_for_list(username, listname)
			for translation in translations: del translation['id']; del translation['list_id']
			
			# Check if is owner
			if username == token_credentials[0]:
				return response_cache_header(json.dumps({
					'listname' : listname,
					'language_1_tag' : list_data.get("language_1_tag"),
					'language_2_tag' : list_data.get("language_2_tag"),
					'words' : translations,
					'shared_with' : shared_with
				}))
			# Check if is friend
			elif shared_with == '1' and db_manager.users_are_friends(username, token_credentials[0]):
				return response_cache_header(json.dumps({
					'listname' : listname,
					'language_1_tag' : list_data.get("language_1_tag"),
					'language_2_tag' : list_data.get("language_2_tag"),
					'words' : translations,
					'shared_with' : shared_with
				}))
			elif shared_with == '2':
				return response_cache_header(json.dumps({
					'listname' : listname,
					'language_1_tag' : list_data.get("language_1_tag"),
					'language_2_tag' : list_data.get("language_2_tag"),
					'words' : translations,
					'shared_with' : shared_with
				}))
			else:
				abort(401)

		else:
			return response_cache_header(json.dumps({"error":"List not found"}), cache_control="no-cache")
	else:
		return response_cache_header(json.dumps({"error":"User not found"}), cache_control="no-cache")
开发者ID:codevbus,项目名称:woording-api,代码行数:56,代码来源:api.py

示例5: friend_request

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_exists [as 别名]
def friend_request():
    db_manager = DatabaseManager()

    username = request.json.get("username")
    friendname = request.json.get("friendname")

    if username == None or friendname == None:
        abort(400)

    if db_manager.username_exists(username) and db_manager.username_exists(friendname):
        if not db_manager.users_are_friends(username, friendname):
            email = db_manager.get_user(friendname).get("email")

            # Email request
            token = generate_confirmation_token([username, friendname])
            confirm_url = "https://api.woording.com/acceptFriend/" + token
            html = render_template("friend.html", confirm_url=confirm_url, name=username)
            subject = "New friend request"
            send_email(email, subject, html)

            return response_cache_header("Email sent", cache_control="no-cache")
        else:
            return response_cache_header("ERROR, already friends", cache_control="no-cache")
开发者ID:woording,项目名称:woording-api,代码行数:25,代码来源:api.py

示例6: friend_request

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_exists [as 别名]
def friend_request():
	db_manager = DatabaseManager()

	username = request.json.get('username')
	friendname = request.json.get('friendname')

	if username == None or friendname == None:
		abort(400)

	if db_manager.username_exists(username) and db_manager.username_exists(friendname):
		if not db_manager.users_are_friends(username, friendname):
			email = db_manager.get_user(friendname).get("email")

			# Email request
			token = generate_confirmation_token([ username, friendname])
			confirm_url = url_for('accept_friend', token=token, _external=True)
			html = render_template('friend.html', confirm_url=confirm_url, name=username)
			subject = "New friend request"
			send_email(email, subject, html)

			return response_cache_header("Email sent", cache_control="no-cache")
		else:
			return response_cache_header("ERROR, already friends", cache_control="no-cache")
开发者ID:codevbus,项目名称:woording-api,代码行数:25,代码来源:api.py

示例7: register

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

示例8: get

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import username_exists [as 别名]
def get(username):
	db_manager = DatabaseManager()

	token = request.json.get('token')
	if token is None or token is "":
		return json.dumps({ 'username':'ERROR, No token' })
	
	# Verifiy token
	token_credentials = db_manager.verify_auth_token(token=token)
	if token_credentials is None:
		return json.dumps({ 'username':'ERROR, No user' })
	elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
		return json.dumps({ 'username':'ERROR, Wrong token'})
	
	if db_manager.username_exists(username):
		# Return all lists
		if token_credentials[0] == username:
			user_info = db_manager.get_user(username)
			list_lists = db_manager.get_lists_for_user(username)
			for l in list_lists: del l['user_id']; del l['id']

			return json.dumps({
				'username': user_info.get("username"),
				'email' : user_info.get("email"),
				'lists' : list_lists
				})
		# Return friend lists if you are friends
		elif db_manager.users_are_friends(username, token_credentials[0]):
			user_info = db_manager.get_user(username)
			list_lists = db_manager.get_lists_for_user(username)
			for l in list_lists:
				if l['shared_with'] == "0":
					list_lists.remove(l)
				del l['user_id']
				del l['id']

			return json.dumps({
				'username': user_info.get("username"),
				'email' : user_info.get("email"),
				'lists' : list_lists
				})
		# Return everyone shared lists
		else:
			user_info = db_manager.get_user(username)
			list_lists = db_manager.get_lists_for_user(username)
			for l in list_lists:
				if l['shared_with'] != "2":
					list_lists.remove(l)
				del l['user_id']
				del l['id']

			return json.dumps({
				'username': user_info.get("username"),
				'email' : user_info.get("email"),
				'lists' : list_lists
				})

	else:
		return json.dumps({
			'username': 'ERROR: This shouldn\'t happen'
			})
开发者ID:Heasummn,项目名称:woording-api,代码行数:63,代码来源:api.py


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