def verify_token(token):
""" Verify the supplied token and check user role is correct for the requested resource"""
if not token:
current_app.logger.debug(f'Token not supplied {request.base_url}')
return False
try:
decoded_token = base64.b64decode(token).decode('utf-8')
except UnicodeDecodeError:
current_app.logger.debug(f'Unable to decode token {request.base_url}')
return False # Can't decode token, so fail login
valid_token, user_id = AuthenticationService.is_valid_token(decoded_token, 604800)
if not valid_token:
current_app.logger.debug(f'Token not valid {request.base_url}')
return False
if tm.is_pm_only_resource:
if not UserService.is_user_a_project_manager(user_id):
current_app.logger.debug(f'User {user_id} is not a PM {request.base_url}')
return False
tm.authenticated_user_id = user_id # Set the user ID on the decorator as a convenience
return True # All tests passed token is good for the requested resource
评论列表
文章目录