Merge branch 'development' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into development

This commit is contained in:
Uwais Al-Qarni
2022-04-26 21:52:53 +08:00
5 changed files with 42 additions and 7 deletions
@@ -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,
]);
}
+13
View File
@@ -50,6 +50,19 @@ 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()) {
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
+3 -4
View File
@@ -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')];
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'));
}
}
+20 -2
View File
@@ -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);
+1
View File
@@ -6,6 +6,7 @@
'routes' => collect(\Route::getRoutes())->mapWithKeys(function ($route) { return [$route->getName() => $route->uri()]; })
]) !!};
</script>
<script type="text/javascript">window.$crisp=[];window.CRISP_WEBSITE_ID="665dcd41-1edf-4451-8cb9-f1cf9ed35e15";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();</script>
<script src="{{ asset('js/vendor.js') }}" type="text/javascript"></script>
<script src="{{mix('vue/app.js')}}"></script>
<script src="{{ asset('js/site.js') }}" type="text/javascript"></script>