本文整理汇总了Python中database.DatabaseManager.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.get_user方法的具体用法?Python DatabaseManager.get_user怎么用?Python DatabaseManager.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.get_user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_user [as 别名]
def authenticate():
db_manager = DatabaseManager()
username = request.json.get("username")
password = sha512_crypt.encrypt(
request.json.get("password"), salt=app.config["SECURITY_PASSWORD_SALT"], rounds=5000
)
if username and password:
if db_manager.get_user(username):
if db_manager.get_user(username).get("email_verified"):
# Check password
if db_manager.check_password(username, password):
token = db_manager.generate_auth_token(username.lower(), password).decode("utf-8")
user_id = db_manager.get_user(username).get("id")
return response_cache_header(json.dumps({"token": token, "success": True}))
else:
return response_cache_header(
json.dumps({"error": "Incorrect password and/or username", "success": False}),
cache_control="no-cache",
)
else:
return response_cache_header(
json.dumps({"error": "Email not verified", "success": False}), cache_control="no-cache"
)
else:
return response_cache_header(
json.dumps({"error": "User does not exist", "success": False}), cache_control="no-cache"
)
else:
return Response("Login!", 401, {"WWW-Authenticate": 'Basic realm="Login!"'})
示例2: get
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_user [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")
示例3: authenticate
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_user [as 别名]
def authenticate():
db_manager = DatabaseManager()
username = request.json.get('username')
password = sha512_crypt.encrypt(request.json.get('password'), salt=app.config['SECURITY_PASSWORD_SALT'], rounds=5000)
if username and password:
if db_manager.get_user(username):
if db_manager.get_user(username).get('email_verified'):
# Check password
if db_manager.check_password(username, password):
return response_cache_header(json.dumps({
"token": db_manager.generate_auth_token(username, password).decode("utf-8")
}))
else:
return response_cache_header(json.dumps({"error":"Email not verified"}), cache_control="no-cache")
else:
return response_cache_header(json.dumps({"error":"User not found"}), cache_control="no-cache")
else:
return Response('Login!', 401, {'WWW-Authenticate': 'Basic realm="Login!"'})
示例4: friend_request
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_user [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")
示例5: friend_request
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_user [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")
示例6: get
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import get_user [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'
})