def get_user_by_api_key(api_key, active_only=False):
"""
Get a User object by api_key, whose attributes match those in the database.
:param api_key: API key to query by
:param active_only: Set this flag to True to only query for active users
:return: User object for that user ID
:raises UserDoesNotExistException: If no user exists with the given user_id
"""
if active_only:
user = models.User.query.filter_by(api_key=api_key, is_active=True).first()
else:
user = models.User.query.filter_by(api_key=api_key).first()
if not user:
raise UserDoesNotExistException('No user with api_key {api_key} exists'.format(api_key=api_key))
return user
评论列表
文章目录