本文整理汇总了Python中database.DatabaseManager.generate_auth_token方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.generate_auth_token方法的具体用法?Python DatabaseManager.generate_auth_token怎么用?Python DatabaseManager.generate_auth_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.generate_auth_token方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authenticate
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import generate_auth_token [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: authenticate
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import generate_auth_token [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!"'})