def get_user(cls, token):
"""Use this function to validate tokens sent by users."""
# Decode token, try to fetch and verify key, and if so return user
# DEVELOPMENT ACCESS
if current_app.config.get("DEBUG") == True:
if token == current_app.config.get("DEV_CRON_API_KEY"):
return user_model.User.query.filter_by(
email=current_app.config.get("DEV_CRON_EMAIL")).first()
s = Signer(current_app.config["SECRET_KEY"])
try:
data = s.loads(token.strip()) # Remove whitespace
except:
return None
if not data.get("id"):
return None
if not data.get("key"):
return None
apikey = ApiKey.query.get(data.get("id"))
if apikey is not None:
if apikey.verify_key(data.get("key")):
return user_model.User.query.get(apikey.user_id)
return None
评论列表
文章目录