You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/04/29 21:29:41 UTC

[airavata-django-portal] 03/03: AIRAVATA-3455 Offer to resend verification link

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 a6c97037f338139a99ddb3464b078e9f6b0e293c
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Apr 29 17:29:25 2021 -0400

    AIRAVATA-3455 Offer to resend verification link
---
 .../static/django_airavata_api/js/service_config.js |  8 ++++++--
 django_airavata/apps/auth/serializers.py            |  5 ++---
 .../js/components/UserProfileEditor.vue             |  4 +++-
 .../js/containers/UserProfileContainer.vue          | 21 ++++++++++++++++++++-
 django_airavata/apps/auth/views.py                  |  8 ++++++++
 5 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
index edbe06c..fb2392b 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/service_config.js
@@ -376,8 +376,12 @@ export default {
     methods: {
       current: {
         url: "/auth/users/current/",
-        requestType: "get"
-      }
+        requestType: "get",
+      },
+      resendEmailVerification: {
+        url: "/auth/users/<lookup>/resend_email_verification/",
+        requestType: "post",
+      },
     },
     modelClass: User,
   },
diff --git a/django_airavata/apps/auth/serializers.py b/django_airavata/apps/auth/serializers.py
index 5b4b929..d5134bb 100644
--- a/django_airavata/apps/auth/serializers.py
+++ b/django_airavata/apps/auth/serializers.py
@@ -47,7 +47,7 @@ class UserSerializer(serializers.ModelSerializer):
             # Email doesn't get updated until it is verified. Create a pending
             # email change record in the meantime
             pending_email_change = models.PendingEmailChange.objects.create(user=request.user, email_address=validated_data['email'])
-            self._send_email_verification_link(pending_email_change)
+            self._send_email_verification_link(request, pending_email_change)
         instance.save()
         # save in the user profile service too
         user_profile_client = request.profile_service['user_profile']
@@ -58,9 +58,8 @@ class UserSerializer(serializers.ModelSerializer):
         user_profile_client.updateUserProfile(request.authz_token, airavata_user_profile)
         return instance
 
-    def _send_email_verification_link(self, pending_email_change):
+    def _send_email_verification_link(self, request, pending_email_change):
 
-        request = self.context['request']
         verification_uri = request.build_absolute_uri(
             reverse(
                 'django_airavata_auth:verify_email_change', kwargs={
diff --git a/django_airavata/apps/auth/static/django_airavata_auth/js/components/UserProfileEditor.vue b/django_airavata/apps/auth/static/django_airavata_auth/js/components/UserProfileEditor.vue
index ce84e61..c80a6d1 100644
--- a/django_airavata/apps/auth/static/django_airavata_auth/js/components/UserProfileEditor.vue
+++ b/django_airavata/apps/auth/static/django_airavata_auth/js/components/UserProfileEditor.vue
@@ -16,7 +16,9 @@
         <strong>{{ user.pending_email_change.email_address }}</strong
         >, your email address will be updated. If you didn't receive the
         verification email,
-        <b-link>click here to resend verification link.</b-link></b-alert
+        <b-link @click="$emit('resend-email-verification')"
+          >click here to resend verification link.</b-link
+        ></b-alert
       >
     </b-form-group>
     <b-button variant="primary" @click="$emit('save', user)">Save</b-button>
diff --git a/django_airavata/apps/auth/static/django_airavata_auth/js/containers/UserProfileContainer.vue b/django_airavata/apps/auth/static/django_airavata_auth/js/containers/UserProfileContainer.vue
index fa210bb..e34e269 100644
--- a/django_airavata/apps/auth/static/django_airavata_auth/js/containers/UserProfileContainer.vue
+++ b/django_airavata/apps/auth/static/django_airavata_auth/js/containers/UserProfileContainer.vue
@@ -1,13 +1,19 @@
 <template>
   <div>
     <h1 class="h4 mb-4">User Profile Editor</h1>
-    <user-profile-editor v-if="user" v-model="user" @save="onSave" />
+    <user-profile-editor
+      v-if="user"
+      v-model="user"
+      @save="onSave"
+      @resend-email-verification="resendEmailVerification"
+    />
   </div>
 </template>
 
 <script>
 import { services } from "django-airavata-api";
 import UserProfileEditor from "../components/UserProfileEditor.vue";
+import { notifications } from "django-airavata-common-ui";
 
 export default {
   components: { UserProfileEditor },
@@ -31,6 +37,19 @@ export default {
         this.user = user;
       });
     },
+    resendEmailVerification() {
+      services.UserService.resendEmailVerification({
+        lookup: this.user.id,
+      }).then(() => {
+        notifications.NotificationList.add(
+          new notifications.Notification({
+            type: "SUCCESS",
+            message: "Verification link sent",
+            duration: 5,
+          })
+        );
+      });
+    },
   },
 };
 </script>
diff --git a/django_airavata/apps/auth/views.py b/django_airavata/apps/auth/views.py
index 3fc0c40..5261b07 100644
--- a/django_airavata/apps/auth/views.py
+++ b/django_airavata/apps/auth/views.py
@@ -545,6 +545,14 @@ class UserViewSet(viewsets.ModelViewSet):
     def current(self, request):
         return redirect(reverse('django_airavata_auth:user-detail', kwargs={'pk': request.user.id}))
 
+    @action(methods=['post'], detail=True)
+    def resend_email_verification(self, request, pk=None):
+        pending_email_change = models.PendingEmailChange.objects.get(user=request.user, verified=False)
+        if pending_email_change is not None:
+            serializer = serializers.UserSerializer()
+            serializer._send_email_verification_link(request, pending_email_change)
+        return JsonResponse({})
+
 
 @login_required
 @atomic