airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isjar...@apache.org
Subject [airavata-custos-portal] branch ux-improvement updated: gh-37: Adding a $route listener to the header component that validates the user
Date Mon, 12 Oct 2020 23:34:41 GMT
This is an automated email from the ASF dual-hosted git repository.

isjarana pushed a commit to branch ux-improvement
in repository https://gitbox.apache.org/repos/asf/airavata-custos-portal.git


The following commit(s) were added to refs/heads/ux-improvement by this push:
     new 3968827  gh-37: Adding a $route listener to the header component that validates the
user
     new 73b1015  Merge pull request #56 from dinukadesilva/gh-37-fix-top-header-component
3968827 is described below

commit 3968827c85a11d3a71d0c133098362e76b598b7e
Author: Dinuka De Silva <L.dinukadesilva@gmail.com>
AuthorDate: Tue Oct 13 02:00:45 2020 +0530

    gh-37: Adding a $route listener to the header component that validates the user
---
 custos-demo-gateway/src/components/Callback.vue    | 32 +------
 custos-demo-gateway/src/components/Header.vue      | 98 +++++++++++-----------
 .../src/components/landing/Landing.vue             | 22 +----
 .../src/components/workspace/Workspace.vue         | 24 ------
 4 files changed, 51 insertions(+), 125 deletions(-)

diff --git a/custos-demo-gateway/src/components/Callback.vue b/custos-demo-gateway/src/components/Callback.vue
index ba63380..f4f3800 100644
--- a/custos-demo-gateway/src/components/Callback.vue
+++ b/custos-demo-gateway/src/components/Callback.vue
@@ -46,37 +46,9 @@
             this.custosSec = config.value('clientSec')
             this.redirectURI = config.value('redirectURI')
             this.tokenEndpoint = "https://custos.scigap.org/apiserver/identity-management/v1.0.0/token"
+
             await this.authenticate()
-            console.log("calling authenticate")
-            if (this.isAuthenticated) {
-                console.log("calling authenticated")
-                let username = await this.$store.dispatch('identity/getCurrentUserName')
-                await this.$router.push('workspace')
-                let data = {
-                    offset: 0, limit: 1, client_id: this.custosId, client_sec: this.custosSec,
-                    username: username
-                }
-                let resp = await this.$store.dispatch('user/users', data)
-                console.log(resp)
-                if (Array.isArray(resp) && resp.length > 0) {
-                    resp.forEach(user => {
-                        let dat = {
-                            client_id: this.custosId,
-                            client_sec: this.custosSec,
-                            body: {
-                                username: user.username,
-                                first_name: user.first_name,
-                                last_name: user.last_name,
-                                email: user.email,
-                            }
-                        }
-                        console.log(dat)
-                        this.$store.dispatch('user/updateUserProfile', dat)
-                    })
-                }
-            } else {
-                await this.$router.push('home')
-            }
+            await this.$router.push('workspace')
         }
     }
 </script>
diff --git a/custos-demo-gateway/src/components/Header.vue b/custos-demo-gateway/src/components/Header.vue
index 266fc30..0fe1acd 100644
--- a/custos-demo-gateway/src/components/Header.vue
+++ b/custos-demo-gateway/src/components/Header.vue
@@ -51,19 +51,14 @@
 </template>
 
 <script>
-
     import config from "@/config";
-    import store from "../store";
 
     export default {
         name: "Header",
         data: function () {
             return {
-                custosId: null,
-                custosSec: null,
                 isAdmin: false,
                 user: null,
-                currentUserName: null,
                 authenticated: false
             }
         },
@@ -72,62 +67,63 @@
                 return this.authenticated
             },
             async logout() {
-                let data = {
-                    client_id: this.custosId,
-                    client_sec: this.custosSec
-                }
-                await this.$store.dispatch('identity/logout', data)
-
-
-                // TODO fix in https://github.com/apache/airavata-custos-portal/issues/37
-                window.location.reload()
+                await this.$store.dispatch('identity/logout', {
+                    client_id: config.value('clientId'),
+                    client_sec: config.value('clientSec'),
+                })
 
-                // await this.$router.push("/")
-                // await this.$store.dispatch('agent/reset')
-                // await this.$store.dispatch('group/reset')
-                // await this.$store.dispatch('secret/reset')
-                // await this.$store.dispatch('sharing/reset')
-                // await this.$store.dispatch('user/reset')
+                await this.$router.push("/")
+                await this.$store.dispatch('agent/reset')
+                await this.$store.dispatch('group/reset')
+                await this.$store.dispatch('secret/reset')
+                await this.$store.dispatch('sharing/reset')
+                await this.$store.dispatch('user/reset')
             },
             async validateAuthentication() {
-                this.authenticated = await store.dispatch('identity/isAuthenticated', {
-                    client_id: process.env.VUE_APP_CLIENT_ID,
-                    client_sec: process.env.VUE_APP_CLIENT_SEC
+                this.authenticated = await this.$store.dispatch('identity/isAuthenticated',
{
+                    client_id: config.value('clientId'),
+                    client_sec: config.value('clientSec')
                 }) === true
 
                 return this.authenticated
-            }
-        },
-
-
-        async mounted() {
-            if (await this.validateAuthentication()) {
-                this.custosId = config.value('clientId')
-                this.custosSec = config.value('clientSec')
+            },
+            async fetchAuthenticatedUser() {
                 this.isAdmin = await this.$store.dispatch('identity/isLoggedUserHasAdminAccess')
-                this.currentUserName = await this.$store.dispatch('identity/getCurrentUserName')
-
-                let resp = await this.$store.dispatch('user/users', {
-                    offset: 0,
-                    limit: 1,
-                    client_id: this.custosId,
-                    client_sec: this.custosSec,
-                    username: this.currentUserName
-                })
-                if (Array.isArray(resp) && resp.length > 0) {
-                    resp.forEach(obj => {
-                        this.user = {
-                            username: obj.username,
-                            first_name: obj.first_name,
-                            last_name: obj.last_name,
-                            email: obj.email,
-                            status: obj.state,
-                            attributes: [],
-                            roles: []
-                        }
+                let currentUserName = await this.$store.dispatch('identity/getCurrentUserName')
+
+                if (await this.validateAuthentication() && (!this.user || this.user.username
!== currentUserName)) {
+                    let resp = await this.$store.dispatch('user/users', {
+                        offset: 0,
+                        limit: 1,
+                        client_id: config.value('clientId'),
+                        client_sec: config.value('clientSec'),
+                        username: currentUserName
                     })
+                    if (Array.isArray(resp) && resp.length > 0) {
+                        resp.forEach(obj => {
+                            this.user = {
+                                username: obj.username,
+                                first_name: obj.first_name,
+                                last_name: obj.last_name,
+                                email: obj.email,
+                                status: obj.state,
+                                attributes: [],
+                                roles: []
+                            }
+                        })
+                    }
                 }
             }
+        },
+        watch: {
+            $route(to, from) {
+                this.authenticated = false
+                console.log("=== route  ", [to, from])
+                this.fetchAuthenticatedUser()
+            }
+        },
+        async beforeMount() {
+            this.fetchAuthenticatedUser()
         }
     }
 </script>
diff --git a/custos-demo-gateway/src/components/landing/Landing.vue b/custos-demo-gateway/src/components/landing/Landing.vue
index 720d1ad..4a4a0b3 100644
--- a/custos-demo-gateway/src/components/landing/Landing.vue
+++ b/custos-demo-gateway/src/components/landing/Landing.vue
@@ -87,7 +87,6 @@
             }
         },
         methods: {
-
             async login() {
                 this.loginDisabled = true
                 if (this.username != null && this.username != '' && this.password
!= null && this.password != '') {
@@ -102,11 +101,7 @@
                     await this.$store.dispatch('identity/authenticateLocally', params)
                     let resp = await this.$store.dispatch('identity/isAuthenticated', data)
                     if (resp) {
-
-                        // TODO fix in https://github.com/apache/airavata-custos-portal/issues/37
-                        window.location.reload()
-
-                        // await this.$router.push('workspace')
+                        await this.$router.push('workspace')
                     } else {
                         this.loginError = true
                     }
@@ -115,8 +110,6 @@
                 }
                 this.loginDisabled = false
             },
-
-
             async callDismissed() {
                 this.loginError = false
             },
@@ -126,7 +119,6 @@
                 window.location.href = this.$store.getters['identity/getAuthorizationEndpoint']
             }
         },
-
         async mounted() {
             this.custosId = config.value('clientId')
             this.custosSec = config.value('clientSec')
@@ -136,20 +128,10 @@
                 client_id: this.custosId,
                 client_sec: this.custosSec
             }
-            if (await store.dispatch('identity/isAuthenticated', data) == true) {
-
+            if (await store.dispatch('identity/isAuthenticated', data) === true) {
                 await this.$router.push('workspace')
             }
-
-        },
-
-        computed: {
-            // ...mapGetters({
-            //
-            // })
         }
-
-
     }
 </script>
 
diff --git a/custos-demo-gateway/src/components/workspace/Workspace.vue b/custos-demo-gateway/src/components/workspace/Workspace.vue
index 041c98a..13d5eb1 100644
--- a/custos-demo-gateway/src/components/workspace/Workspace.vue
+++ b/custos-demo-gateway/src/components/workspace/Workspace.vue
@@ -44,8 +44,6 @@
 </template>
 
 <script>
-    import config from "@/config";
-
     export default {
         name: "Workspace",
         data: function () {
@@ -75,30 +73,8 @@
                 await this.$store.dispatch('user/reset')
             }
         },
-
         async mounted() {
-            this.custosId = config.value('clientId')
-            this.custosSec = config.value('clientSec')
             this.isAdmin = await this.$store.dispatch('identity/isLoggedUserHasAdminAccess')
-            this.currentUserName = await this.$store.dispatch('identity/getCurrentUserName')
-            let data = {
-                offset: 0, limit: 1, client_id: this.custosId, client_sec: this.custosSec,
-                username: this.currentUserName
-            }
-            let resp = await this.$store.dispatch('user/users', data)
-            if (Array.isArray(resp) && resp.length > 0) {
-                resp.forEach(obj => {
-                    this.user = {
-                        username: obj.username,
-                        first_name: obj.first_name,
-                        last_name: obj.last_name,
-                        email: obj.email,
-                        status: obj.state,
-                        attributes: [],
-                        roles: []
-                    }
-                })
-            }
         }
     }
 </script>


Mime
View raw message