Skip to content
Snippets Groups Projects
Commit d84f0b27 authored by moon's avatar moon
Browse files

Added the security check according to the role

parent 29373e4f
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<div v-if="loading || response === null"></div> <div v-if="loading || response === null"></div>
<div v-else> <div v-else>
<!-- {{response}}--> <!-- {{response}}-->
<h4 class="round">User Profile</h4> <h4 class="round">User Profile</h4>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
...@@ -26,7 +25,7 @@ ...@@ -26,7 +25,7 @@
<div class="row"> <div class="row">
<div class="text col-sm-3">Role</div> <div class="text col-sm-3">Role</div>
<div class="col-sm-9"> <div class="col-sm-9">
{{$store.dispatch('User/setUserRole', response.role.name) && response.role.name}} {{setRole(response.role.name)}}
</div> </div>
</div> </div>
<div class="row"> <div class="row">
...@@ -108,6 +107,12 @@ export default { ...@@ -108,6 +107,12 @@ export default {
}, },
}, },
methods: { methods: {
setRole(roleName) {
const vm = this
window.localStorage.setItem('roleName', roleName)
vm.$store.dispatch('User/setUserRole', roleName)
return roleName
},
}, },
mounted: function () { mounted: function () {
const vm = this const vm = this
......
<template> <template>
<div> <div>
<div class="flex items-center justify-center"> <div class="flex items-center justify-center">
<div class="md:flex card p-2 mt-5"> <h3 v-show="error" class="text-2xl text-red-500">{{ errorMsg }}</h3>
<div v-if="loaded" class="md:flex card p-2 mt-5">
<div class="p-5 mx-auto text-left font-raleway container max-w-screen-md"> <div class="p-5 mx-auto text-left font-raleway container max-w-screen-md">
<h1 class="font-bold text-left font-montserrat text-3xl sm:text-5xl mb-7"> <h1 class="font-bold text-left font-montserrat text-3xl sm:text-5xl mb-7">
{{ item === 'new'? 'Create new Update Item' : item }} {{ item === 'new'? 'Create new Update Item' : item }}
</h1> </h1>
<p v-show="error" class="text-lg text-red-500">{{ errorMsg }}</p>
<form @submit="update" class="w-full md:w-auto"> <form @submit="update" class="w-full md:w-auto">
<div class="md:flex md:items-center mx-3 mb-6"> <div class="md:flex md:items-center mx-3 mb-6">
<div class="md:w-1/3"> <div class="md:w-1/3">
...@@ -154,6 +154,7 @@ export default { ...@@ -154,6 +154,7 @@ export default {
syncedAt: '', // datetime syncedAt: '', // datetime
syncResponse: '', // response from the sync process (errors if any) syncResponse: '', // response from the sync process (errors if any)
comment: '', // user comment comment: '', // user comment
loaded: false,
error: false, error: false,
errorMsg: `An error occurred, please try again` errorMsg: `An error occurred, please try again`
} }
...@@ -176,8 +177,7 @@ export default { ...@@ -176,8 +177,7 @@ export default {
const jwt = vm.jwt; const jwt = vm.jwt;
if(jwt === null) { if(jwt === null) {
vm.loading = false; vm.loaded = false;
vm.response = null;
return return
} }
...@@ -218,10 +218,10 @@ export default { ...@@ -218,10 +218,10 @@ export default {
// console.log(res) // console.log(res)
this.$router.push('/profile') vm.$router.push('/profile')
} catch(error) { } catch(error) {
// console.log(error.response.data.error.message) // console.log(error.response.data.error.message)
console.log(error.response) // console.log(error.response)
this.error = true this.error = true
this.errorMsg = error this.errorMsg = error
} }
...@@ -231,8 +231,7 @@ export default { ...@@ -231,8 +231,7 @@ export default {
const jwt = vm.jwt; const jwt = vm.jwt;
if(jwt === null) { if(jwt === null) {
vm.loading = false; vm.loaded = false;
vm.response = null;
return return
} }
...@@ -263,17 +262,26 @@ export default { ...@@ -263,17 +262,26 @@ export default {
// SyncedAt: // SyncedAt:
// SyncResponse: // SyncResponse:
} }
vm.loaded = true;
} catch(error) { } catch(error) {
console.log(error) // console.error(error)
this.error = true this.error = true
this.errorMsg = error this.errorMsg = "You are not authorized to access this item."
setTimeout(() => vm.$router.go(-1), 2000);
} }
} }
}, },
mounted: function () { mounted: function () {
const vm = this const vm = this;
if(vm.item !== 'new') {
vm.load(vm.item) const jwt = vm.jwt;
if(jwt === null) {
vm.$router.push('/login')
} else {
if(vm.item !== 'new') {
vm.load(vm.item)
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment