This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch 
AIRAVATA-3319-handle-missing-name-and-email-attributes-from-cilo
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit b1980fb72dc1f622d3c9f51966edf0eca6ea9835
Author: Marcus Christie <[email protected]>
AuthorDate: Tue Jun 8 16:07:21 2021 -0400

    AIRAVATA-3455 Add error handling to email verification process
---
 django_airavata/apps/auth/views.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/django_airavata/apps/auth/views.py 
b/django_airavata/apps/auth/views.py
index dfa9c22..fb30761 100644
--- a/django_airavata/apps/auth/views.py
+++ b/django_airavata/apps/auth/views.py
@@ -560,17 +560,23 @@ class UserViewSet(viewsets.ModelViewSet):
         user = self.get_object()
         code = request.data['code']
 
-        pending_email_change = 
models.PendingEmailChange.objects.get(user=user, verification_code=code)
+        try:
+            pending_email_change = 
models.PendingEmailChange.objects.get(user=user, verification_code=code)
+        except models.PendingEmailChange.DoesNotExist:
+            raise Exception('Verification code is invalid. Please try again.')
         pending_email_change.verified = True
         pending_email_change.save()
         user.email = pending_email_change.email_address
         user.save()
         user.refresh_from_db()
 
-        user_profile_client = request.profile_service['user_profile']
-        airavata_user_profile = user_profile_client.getUserProfileById(
-            request.authz_token, user.username, settings.GATEWAY_ID)
-        airavata_user_profile.emails = [pending_email_change.email_address]
-        user_profile_client.updateUserProfile(request.authz_token, 
airavata_user_profile)
+        try:
+            user_profile_client = request.profile_service['user_profile']
+            airavata_user_profile = user_profile_client.getUserProfileById(
+                request.authz_token, user.username, settings.GATEWAY_ID)
+            airavata_user_profile.emails = [pending_email_change.email_address]
+            user_profile_client.updateUserProfile(request.authz_token, 
airavata_user_profile)
+        except Exception as e:
+            raise Exception(f"Failed to update Airavata User Profile with new 
email address: {e}") from e
         serializer = self.get_serializer(user)
         return Response(serializer.data)

Reply via email to