Commit 28df8be7 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

add bearer token

parent 66e7f51a
...@@ -56,7 +56,7 @@ export default { ...@@ -56,7 +56,7 @@ export default {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
accept: "application/json", "accept": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
token: this.$auth.$storage.getUniversal("token"), token: this.$auth.$storage.getUniversal("token"),
......
...@@ -308,7 +308,11 @@ export default { ...@@ -308,7 +308,11 @@ export default {
}, },
getCategories() { getCategories() {
this.$axios this.$axios
.get("/categories/") .get("/categories/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.categories = response.data.data)) .then((response) => (this.categories = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -319,17 +323,20 @@ export default { ...@@ -319,17 +323,20 @@ export default {
const image = Array.from(set) const image = Array.from(set)
const self = this const self = this
this.$axios this.$axios
.post('/categories/',{ .post('/categories/',
name: this.name, {
ordering: this.ordering, name: this.name,
parent_id: this.parent_id, ordering: this.ordering,
images: image, parent_id: this.parent_id,
}, { images: image,
headers: { },
"Content-Type": "multipart/form-data", {
"Authorization": this.$auth.$storage.getUniversal("token") headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
} }
}) )
.then(response => { .then(response => {
this.$bvModal.hide('modal-create') this.$bvModal.hide('modal-create')
self.$toast.success('Category created successfully!', { self.$toast.success('Category created successfully!', {
...@@ -362,7 +369,13 @@ export default { ...@@ -362,7 +369,13 @@ export default {
if(confirm("Do you really want to delete?")){ if(confirm("Do you really want to delete?")){
try{ try{
this.$axios this.$axios
.delete(`/categories/${ID}`) .delete(`/categories/${ID}`,
{
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
})
.then(response => { .then(response => {
this.categories.splice(this.editedIndex, 1) this.categories.splice(this.editedIndex, 1)
self.$toast.success('Category deleted successfully!',{ self.$toast.success('Category deleted successfully!',{
...@@ -397,16 +410,19 @@ export default { ...@@ -397,16 +410,19 @@ export default {
console.log(this?.eID) console.log(this?.eID)
try{ try{
this.$axios this.$axios
.post(`categories/update/${this?.eID}`,{ .post(`categories/update/${this?.eID}`,
name: this.eName, {
ordering: this.eOrdering, name: this.eName,
parent_id: this.eParentId, ordering: this.eOrdering,
images: image }, { parent_id: this.eParentId,
headers: { images: image },
"Content-Type": "multipart/form-data", {
"Authorization": this.$auth.$storage.getUniversal("token") headers: {
} "Content-Type": "multipart/form-data",
} ) Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}
}
)
.then(response => { .then(response => {
self.$toast.success('User updated successfully!',{ self.$toast.success('User updated successfully!',{
duration: 3000 duration: 3000
......
...@@ -386,7 +386,11 @@ export default { ...@@ -386,7 +386,11 @@ export default {
}, },
getCategories() { getCategories() {
this.$axios this.$axios
.get("/categories/") .get("/categories/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.categories = response.data.data)) .then((response) => (this.categories = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -394,7 +398,11 @@ export default { ...@@ -394,7 +398,11 @@ export default {
}, },
getposts() { getposts() {
this.$axios this.$axios
.get("/posts/") .get("/posts/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.posts = response.data.data)) .then((response) => (this.posts = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -415,7 +423,7 @@ export default { ...@@ -415,7 +423,7 @@ export default {
{ {
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal("token"), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
} }
) )
...@@ -442,7 +450,11 @@ export default { ...@@ -442,7 +450,11 @@ export default {
this.editedIndex = this.posts.indexOf(index) this.editedIndex = this.posts.indexOf(index)
if (confirm("Do you really want to delete?")) { if (confirm("Do you really want to delete?")) {
this.$axios this.$axios
.delete(`/posts/${ID}`) .delete(`/posts/${ID}`,{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => { .then((response) => {
this.posts.splice(this.editedIndex, 1) this.posts.splice(this.editedIndex, 1)
self.$toast.success("Post deleted successfully!", { self.$toast.success("Post deleted successfully!", {
...@@ -464,7 +476,7 @@ export default { ...@@ -464,7 +476,7 @@ export default {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal("token"), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
}) })
console.log(resp.data) console.log(resp.data)
...@@ -505,7 +517,7 @@ export default { ...@@ -505,7 +517,7 @@ export default {
{ {
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal("token"), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
} }
) )
......
...@@ -487,7 +487,11 @@ export default { ...@@ -487,7 +487,11 @@ export default {
}, },
getCategories() { getCategories() {
this.$axios this.$axios
.get("/categories/") .get("/categories/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.categories = response.data.data)) .then((response) => (this.categories = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -495,7 +499,11 @@ export default { ...@@ -495,7 +499,11 @@ export default {
}, },
getProducts() { getProducts() {
this.$axios this.$axios
.get("/products/") .get("/products/",{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then((response) => (this.products = response.data.data)) .then((response) => (this.products = response.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -516,7 +524,7 @@ export default { ...@@ -516,7 +524,7 @@ export default {
}, { }, {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
'Authorization': this.$auth.$storage.getUniversal('token') Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
} }
}) })
.then(response => { .then(response => {
...@@ -543,7 +551,11 @@ export default { ...@@ -543,7 +551,11 @@ export default {
if(confirm("Do you really want to delete?")){ if(confirm("Do you really want to delete?")){
try{ try{
this.$axios this.$axios
.delete(`/products/${ID}`) .delete(`/products/${ID}`,{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}})
.then(response => { .then(response => {
this.products.splice(this.editedIndex, 1) this.products.splice(this.editedIndex, 1)
self.$toast.success('Category deleted successfully!',{ self.$toast.success('Category deleted successfully!',{
...@@ -562,7 +574,7 @@ export default { ...@@ -562,7 +574,7 @@ export default {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
Authorization: this.$auth.$storage.getUniversal("token"), Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}, },
}) })
this.sName = resp.data.data.name this.sName = resp.data.data.name
...@@ -600,11 +612,12 @@ export default { ...@@ -600,11 +612,12 @@ export default {
images: this.eImages, images: this.eImages,
variants: this.eVariants, variants: this.eVariants,
}, { }, {
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
"Authorization": this.$auth.$storage.getUniversal("token") Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
}
} }
} ) )
.then(response => { .then(response => {
self.$toast.success('User updated successfully!',{ self.$toast.success('User updated successfully!',{
duration: 3000 duration: 3000
......
...@@ -86,7 +86,7 @@ export default { ...@@ -86,7 +86,7 @@ export default {
confirm_password: this.confirm_password, confirm_password: this.confirm_password,
}), }),
}); });
this.$router.push("/"); this.$router.push("/login");
}, },
}, },
}; };
......
...@@ -295,7 +295,12 @@ export default { ...@@ -295,7 +295,12 @@ export default {
}, },
getUsers() { getUsers() {
this.$axios this.$axios
.get('/users/') .get('/users/',{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
})
.then((response) => (this.users = response.data.data.data)) .then((response) => (this.users = response.data.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error) console.log(error)
...@@ -304,14 +309,19 @@ export default { ...@@ -304,14 +309,19 @@ export default {
createUser() { createUser() {
const self = this const self = this
this.$axios this.$axios
.post('/users/',{ .post('/users/',
headers: { {
'Content-Type': 'application/json' email: this.email,
password: this.password,
name:this.name,
}, },
email: this.email, {
password: this.password, headers: {
name:this.name, 'Content-Type': 'application/json',
}) Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
}
)
.then(response => { .then(response => {
// $bvModal.hide('modal-login'); // $bvModal.hide('modal-login');
this.$bvModal.hide('modal-login') this.$bvModal.hide('modal-login')
...@@ -338,7 +348,12 @@ export default { ...@@ -338,7 +348,12 @@ export default {
if(confirm("Do you really want to delete?")){ if(confirm("Do you really want to delete?")){
try{ try{
this.$axios this.$axios
.delete(`/users/${userID}`) .delete(`/users/${userID}`,{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
})
.then(response => { .then(response => {
console.log(response.data) console.log(response.data)
this.users.splice(this.editedIndex, 1) this.users.splice(this.editedIndex, 1)
...@@ -366,10 +381,19 @@ export default { ...@@ -366,10 +381,19 @@ export default {
console.log(this?.eID) console.log(this?.eID)
try{ try{
this.$axios this.$axios
.put(`/users/${this?.eID}`,{ .put(`/users/${this?.eID}`,
email: this.eEmail, {
password: this.ePassword, email: this.eEmail,
name:this.eName,} ) password: this.ePassword,
name:this.eName,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal("token")}`,
},
}
)
.then(response => { .then(response => {
self.$toast.success('User updated successfully!',{ self.$toast.success('User updated successfully!',{
duration: 3000 duration: 3000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment