def google_oauth_one_time_token_auth(auth_code): email = google_helpers.get_email_from_one_time_code(auth_code) token, user_created = core_helpers.get_auth_token_for_email(email) if token is not None: serialiser = core_serializers.WhoAmISerializer(token) if user_created: return Response(serialiser.data, status=status.HTTP_201_CREATED) else: return Response(serialiser.data) else: serialiser = core_serializers.UserErrorSerialiser( data={ "message": f"Please log in with your @{core_constants.BUSINESS_EMAIL_DOMAIN} email address if you have one. Otherwise please talk to an administrator to hook you up" }) assert serialiser.is_valid(), serialiser.errors return Response(serialiser.data, status=status.HTTP_401_UNAUTHORIZED)
def test_internal_email_user_exists(self): user = UserFactory(email=self.internal_email) token, user_created = get_auth_token_for_email(self.internal_email) self.assertIsNotNone(token) self.assertFalse(user_created) self.assertEqual(user, token.user)
def test_outside_email_user_does_not_exist(self): token, user_created = get_auth_token_for_email(self.external_email) self.assertIsNone(token) self.assertFalse(user_created)
def test_internal_email_user_does_not_exist(self): token, user_created = get_auth_token_for_email(self.internal_email) self.assertIsNotNone(token) self.assertTrue(user_created) self.assertEqual(token.user.email, self.internal_email)