+ @property
+ def is_authenticated(self):
+ """Checks for a valid authentication."""
+ if self.token is not None and utils.is_token_valid({'expires': self.token_expires}):
+ return True
+ else:
+ return False
+
+ def get_token(self):
+ if self.is_authenticated:
+ return {'id': self.token, 'expires': self.token_expires, 'project_id': self.project_id}
+ return None
+
+ def switch_project(self, project_id):
+ client = Client()
+ result = client.switch_project({'project_id': project_id, 'username': self.username, 'password': self.psw})
+ if 'error' in result and result['error'] is True:
+ raise OSMAuthException(result['data'])
+ else:
+ self.token = result['data']['id']
+ self.project_id = result['data']['project_id']
+ self.token_expires = result['data']['expires']
+ self.save()
+ return True
+ return False
+