Пример #1
0
def get_outlook_credential(user_id):
  """Fetch the outlook credential from db based on user_id."""
  user = authentication_models.get_user_by_id(user_id)
  if user is None:
    raise ValueError('No user found with id: {0}'.format(user_id))

  credential = authentication_models.OutlookCredentialsModel.objects.get(
      id=user
  )
  if credential is None:
      raise CredentialsException('Credentials not found or invalid.')
  return credential
Пример #2
0
def get_google_credential(user_id):
  """Fetch the google oauth credential from db based on user_id.

  Args:
    user_id: Integer
  Returns:
    oauth2client.client.Credential object
  Raises:
    CredentialsException if credential not found or invalid.
  """
  user = authentication_models.get_user_by_id(user_id)
  if user is None:
    raise ValueError('No user found with id: {0}'.format(user_id))
  storage = django_orm.Storage(authentication_models.CredentialsModel,
                               'id', user, 'credential')
  credential = storage.get()
  if credential is None or credential.invalid:
      raise CredentialsException('Credentials not found or invalid.')
  return credential