本文整理汇总了Python中database.DatabaseManager.get_friends_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.get_friends_for_user方法的具体用法?Python DatabaseManager.get_friends_for_user怎么用?Python DatabaseManager.get_friends_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.get_friends_for_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_friends
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_friends_for_user [as 别名]
def get_friends():
db_manager = DatabaseManager()
username = request.json.get("username").lower()
token = request.json.get("token")
if username == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
friends = db_manager.get_friends_for_user(username)
# It is unsafe to send your friends password hash to the browser... email_verified and id aren't needed
for friend in friends:
if friend == None:
friends.remove(friend)
continue
del friend["password_hash"]
del friend["email_verified"]
del friend["id"]
return response_cache_header(json.dumps({"friends": friends}))
示例2: get_friends
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_friends_for_user [as 别名]
def get_friends():
db_manager = DatabaseManager()
username = request.json.get('username')
token = request.json.get('token')
if username == None or token == None:
abort(400)
# Verifiy token
token_credentials = db_manager.verify_auth_token(token=token)
if token_credentials is None:
abort(401)
elif not db_manager.check_password(token_credentials[0], token_credentials[1]):
abort(401)
elif token_credentials[0] != username:
abort(401)
friends = db_manager.get_friends_for_user(username)
# It is unsafe to send your friends password hash to the browser... email_verified and id aren't needed
for friend in friends: del friend['password_hash']; del friend['email_verified']; del friend['id']
return response_cache_header(json.dumps({"friends":friends}))