From 8678ac7b5e588fb164a8d62bbb9bc31c7220a007 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Mon, 25 Apr 2022 15:14:50 +0800 Subject: [PATCH 1/9] push crisp --- .../Services/GeneratesAuthenticationToken.php | 6 ++++- resources/assets/vue/app.js | 13 +++++++++++ .../assets/vue/vuex/modules/authentication.js | 22 +++++++++++++++++-- resources/views/vendor/js.blade.php | 1 + 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php b/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php index 72296b97..2116895c 100644 --- a/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php +++ b/app/Classes/Modules/Accounts/Services/GeneratesAuthenticationToken.php @@ -65,8 +65,12 @@ class GeneratesAuthenticationToken { ]; if($user->type === RoleTypes::USER) { + + /** @var Company $companyModule */ $claims = array_merge($claims, [ - 'company_id' => $company->id + 'company_id' => $company->id, + 'company_name' => $company->name, + 'company_marking' => $company->reference, ]); } diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index 1d98d12d..ff2da230 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,6 +50,19 @@ const app = new Vue({ store, created(){ this.routesGuard(); + if (!('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { + this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { + let success = response.ok; + response.json().then(response => { + + if(!success){return;} + + this.$store.dispatch('userAuthentication', {access_token: response.payload.refresh_token, redirect_url: window.location.href}); + + }); + }) + + } }, methods: { route: route diff --git a/resources/assets/vue/vuex/modules/authentication.js b/resources/assets/vue/vuex/modules/authentication.js index 19ab2317..f822d26b 100644 --- a/resources/assets/vue/vuex/modules/authentication.js +++ b/resources/assets/vue/vuex/modules/authentication.js @@ -9,8 +9,6 @@ export default { }, getters: { isAuthenticated: state => !!state.authentication.access_token, - getAccessToken: state => state.authentication.access_token, - isSuperAdmin: (state, getters) => getters.getDecodedAccessToken.user.type === 0 || getters.getDecodedAccessToken.user.type === 1, isAdmin: (state, getters) => getters.getDecodedAccessToken.user.type === 0 || getters.getDecodedAccessToken.user.type === 1 || getters.getDecodedAccessToken.user.type === 2, isCustomer: (state, getters) => getters.getDecodedAccessToken.user.type === 3, @@ -19,7 +17,27 @@ export default { getUserId: (state, getters) => getters.getDecodedAccessToken.user.id, getUserEmail: (state, getters) => getters.getDecodedAccessToken.user.email, getCompanyId: (state, getters) => getters.getDecodedAccessToken.user.company_id, + getAccessToken(state, getters, dispatch) { + if(getters.isAuthenticated){ + $crisp.push(["set", "user:email", getters.getUserEmail]); + if(getters.isAdmin){ + $crisp.push(["set", "user:nickname", getters.getUserName]); + } + + if(getters.isCustomer && ('company_marking' in getters.getDecodedAccessToken.user)){ + $crisp.push(["set", "user:nickname", getters.getDecodedAccessToken.user.company_marking]); + $crisp.push(["set", "session:data", [ + [ + ["exchange-marking", getters.getDecodedAccessToken.user.company_marking], + ["company-name", getters.getDecodedAccessToken.user.company_name] + ] + ]]); + } + } + + return state.authentication.access_token + }, getDecodedAccessToken(state) { try{ return jwt_decode(state.authentication.access_token); diff --git a/resources/views/vendor/js.blade.php b/resources/views/vendor/js.blade.php index 9adee26b..41482a0d 100644 --- a/resources/views/vendor/js.blade.php +++ b/resources/views/vendor/js.blade.php @@ -6,6 +6,7 @@ 'routes' => collect(\Route::getRoutes())->mapWithKeys(function ($route) { return [$route->getName() => $route->uri()]; }) ]) !!}; + From 474caac039884c249e77ce1bda049dae022f01b5 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Mon, 25 Apr 2022 15:17:30 +0800 Subject: [PATCH 2/9] push crisp --- resources/assets/vue/app.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index ff2da230..ec252067 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,19 +50,19 @@ const app = new Vue({ store, created(){ this.routesGuard(); - if (!('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { - this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { - let success = response.ok; - response.json().then(response => { - - if(!success){return;} - - this.$store.dispatch('userAuthentication', {access_token: response.payload.refresh_token, redirect_url: window.location.href}); - - }); - }) - - } + // if (!('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { + // this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { + // let success = response.ok; + // response.json().then(response => { + // + // if(!success){return;} + // + // this.$store.dispatch('userAuthentication', {access_token: response.payload.refresh_token, redirect_url: window.location.href}); + // + // }); + // }) + // + // } }, methods: { route: route From 2dddc2299f656a63273777af4ca7b429647ab832 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Mon, 25 Apr 2022 15:18:52 +0800 Subject: [PATCH 3/9] push crisp --- resources/assets/vue/app.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index ec252067..cddcf3a7 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,19 +50,19 @@ const app = new Vue({ store, created(){ this.routesGuard(); - // if (!('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { - // this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { - // let success = response.ok; - // response.json().then(response => { - // - // if(!success){return;} - // - // this.$store.dispatch('userAuthentication', {access_token: response.payload.refresh_token, redirect_url: window.location.href}); - // - // }); - // }) - // - // } + if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { + this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { + let success = response.ok; + response.json().then(response => { + + if(!success){return;} + + this.$store.dispatch('userAuthentication', {access_token: response.payload.refresh_token, redirect_url: window.location.href}); + + }); + }) + + } }, methods: { route: route From 95c538e66ba22f2177a05de7d3e0c1b88191669d Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 26 Apr 2022 12:28:56 +0800 Subject: [PATCH 4/9] fix password reset redirect bug --- resources/assets/vue/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index cddcf3a7..4051dc09 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,7 +50,7 @@ const app = new Vue({ store, created(){ this.routesGuard(); - if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { + if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && (this.isProtectedRoute() || this.isWithTokenRoute())) { this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { let success = response.ok; response.json().then(response => { From 95bf0a5873e638b6c0c50d504def5fe4c9402f2a Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 26 Apr 2022 12:42:37 +0800 Subject: [PATCH 5/9] fix password reset redirect bug --- resources/assets/vue/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index 4051dc09..d9e2e465 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,7 +50,7 @@ const app = new Vue({ store, created(){ this.routesGuard(); - if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && (this.isProtectedRoute() || this.isWithTokenRoute())) { + if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute() && !this.isWithTokenRoute()) { this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { let success = response.ok; response.json().then(response => { From 0f86a514b053264ced9de35bf1247ed1470affeb Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 26 Apr 2022 12:47:41 +0800 Subject: [PATCH 6/9] fix password reset redirect bug --- resources/assets/vue/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index d9e2e465..52b09587 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,7 +50,8 @@ const app = new Vue({ store, created(){ this.routesGuard(); - if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute() && !this.isWithTokenRoute()) { + console.log(!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()); + if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { let success = response.ok; response.json().then(response => { From 4a15e022a70557279f393c8cad6bc3b22e335a6c Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 26 Apr 2022 12:49:17 +0800 Subject: [PATCH 7/9] fix password reset redirect bug --- resources/assets/vue/general/mixins/guards.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/vue/general/mixins/guards.js b/resources/assets/vue/general/mixins/guards.js index 18681e5d..fd152cfe 100644 --- a/resources/assets/vue/general/mixins/guards.js +++ b/resources/assets/vue/general/mixins/guards.js @@ -5,7 +5,7 @@ export default { (this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& this.isWithTokenRoute()) ? window.location.href = this.route('dashboard') : ''; }, isProtectedRoute(){ - const unprotectedRoutes = [this.route('login'), this.route('account.email.verification')]; + const unprotectedRoutes = [this.route('login'), this.route('account.email.verification'), this.route('account.password.reset')]; return !unprotectedRoutes.includes(window.location.href); }, isWithTokenRoute(){ From 8e10d68257a178870a4b26a44984c940feb8d4ee Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 26 Apr 2022 12:49:31 +0800 Subject: [PATCH 8/9] fix password reset redirect bug --- resources/assets/vue/app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index 52b09587..cddcf3a7 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,7 +50,6 @@ const app = new Vue({ store, created(){ this.routesGuard(); - console.log(!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()); if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { let success = response.ok; From 67615168f82eaa38032ef6de34ca0f31b37ce359 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 26 Apr 2022 13:21:11 +0800 Subject: [PATCH 9/9] fix password reset redirect bug --- resources/assets/vue/app.js | 2 +- resources/assets/vue/general/mixins/guards.js | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/resources/assets/vue/app.js b/resources/assets/vue/app.js index cddcf3a7..d9e2e465 100644 --- a/resources/assets/vue/app.js +++ b/resources/assets/vue/app.js @@ -50,7 +50,7 @@ const app = new Vue({ store, created(){ this.routesGuard(); - if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute()) { + if (!this.$store.getters.isAdmin && !('company_marking' in this.$store.getters.getDecodedAccessToken.user) && this.isProtectedRoute() && !this.isWithTokenRoute()) { this.$store.dispatch('crudRequest', {endpoint: this.route('api.account.authentication.refresh'), method: 'get'}).then(response => { let success = response.ok; response.json().then(response => { diff --git a/resources/assets/vue/general/mixins/guards.js b/resources/assets/vue/general/mixins/guards.js index fd152cfe..3b39baad 100644 --- a/resources/assets/vue/general/mixins/guards.js +++ b/resources/assets/vue/general/mixins/guards.js @@ -1,16 +1,15 @@ export default { methods: { routesGuard(){ - (!this.$store.getters.isAuthenticated && this.isProtectedRoute()&& this.isWithTokenRoute()) ? window.location.href = this.route('login') : ''; - (this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& this.isWithTokenRoute()) ? window.location.href = this.route('dashboard') : ''; + (!this.$store.getters.isAuthenticated && this.isProtectedRoute()&& !this.isWithTokenRoute()) ? window.location.href = this.route('login') : ''; + (this.$store.getters.isAuthenticated && !this.isProtectedRoute()&& !this.isWithTokenRoute()) ? window.location.href = this.route('dashboard') : ''; }, isProtectedRoute(){ - const unprotectedRoutes = [this.route('login'), this.route('account.email.verification'), this.route('account.password.reset')]; + const unprotectedRoutes = [this.route('login'), this.route('account.email.verification')]; return !unprotectedRoutes.includes(window.location.href); }, isWithTokenRoute(){ - const unprotectedRoutesWithToken = [this.route('account.password.reset')]; - return !window.location.href.includes(unprotectedRoutesWithToken); + return window.location.href.includes(this.route('account.password.reset')); } }