From 23bbef156090deca4a523e8fb31c92f512345231 Mon Sep 17 00:00:00 2001 From: olarid7852 Date: Fri, 20 Dec 2024 15:05:55 +0100 Subject: [PATCH] Fix resend verification mail (#60) --- apps/users/views.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/users/views.py b/apps/users/views.py index 3803314..21453b6 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -148,13 +148,22 @@ def resend_verification_email(self, request): if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) email = serializer.validated_data["email"] - auth0_account = SocialAccount.objects.get(user__email=email) - if not auth0_account: - return Response({"detail": "Verification email sent successfully"}) - user_id = auth0_account.uid # Get Auth0 management token auth0_token = get_auth0_management_token() + headers = get_auth0_headers(auth0_token) + + response = requests.get( + f"https://{settings.AUTH0_DOMAIN}/api/v2/users-by-email", + params={'email': email}, + headers=headers, + ) + user_json = response.json() + if len(user_json) == 0: + return Response({"detail": "Verification email sent successfully"}) + + user_id = user_json[0]['user_id'] + try: self.send_verification_email(user_id, auth0_token) except requests.RequestException as e: