Commit fe51c5cb authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

add validate posts

parent e8dd1c73
...@@ -389,7 +389,7 @@ export default { ...@@ -389,7 +389,7 @@ export default {
v => (v && v.length <= 255) || 'Name must be less than 255 characters' v => (v && v.length <= 255) || 'Name must be less than 255 characters'
], ],
requiredRules: [ requiredRules: [
v => !!v || 'This field is required', v => !!v || 'This field is required'
], ],
numberRules: [ numberRules: [
v => !!v || 'This field is required', v => !!v || 'This field is required',
......
...@@ -109,10 +109,15 @@ export default { ...@@ -109,10 +109,15 @@ export default {
this.password = '' this.password = ''
this.checkbox = false this.checkbox = false
}, },
async login() { async login () {
try { try {
const resp = await this.$axios.post('/login', const resp = await fetch('http://127.0.0.1:8000/api/login', {
{ method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
email: this.email, email: this.email,
password: this.password, password: this.password,
status: this.status status: this.status
...@@ -121,7 +126,7 @@ export default { ...@@ -121,7 +126,7 @@ export default {
return response.json() return response.json()
}) })
console.log(resp.status) console.log(resp.status)
localStorage.setItem('token', resp.data.bearer_token) localStorage.setItem('token', resp.data.bearer_token)
this.$auth.$storage.setUniversal('token', resp.data.bearer_token) this.$auth.$storage.setUniversal('token', resp.data.bearer_token)
this.$auth.$storage.setUniversal('userName', resp.data.name) this.$auth.$storage.setUniversal('userName', resp.data.name)
this.$auth.$storage.setUniversal('loggedIn', 'true') this.$auth.$storage.setUniversal('loggedIn', 'true')
...@@ -132,13 +137,13 @@ export default { ...@@ -132,13 +137,13 @@ export default {
this.$router.push('home') this.$router.push('home')
} }
} catch (e) { } catch (e) {
this.$toast.error("Username or Password not valid", { this.$toast.error('Username or Password not valid', {
duration: 2000, duration: 2000
}); })
this.$router.push("/login"); this.$router.push('/login')
} }
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
......
...@@ -68,9 +68,9 @@ ...@@ -68,9 +68,9 @@
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<!-- <v-col v-for="(image, index) in sImages" :key="index" cols="12"> <!-- <v-col v-for="(image, index) in sImages" :key="index" cols="12">
<v-img :src="image"/> --> <v-img :src="image"/> </v-col> -->
<v-img <v-img
v-if="typeof sImages === 'string'" v-if="typeof sImages == 'string'"
:src="sImages" :src="sImages"
/> />
</v-col> </v-col>
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
v-model="dialog" v-model="dialog"
persistent persistent
max-width="600px" max-width="600px"
lazy-validation
> >
<v-card> <v-card>
<v-card-title> <v-card-title>
...@@ -111,6 +112,7 @@ ...@@ -111,6 +112,7 @@
<v-text-field <v-text-field
v-model="eTitle" v-model="eTitle"
label="Title*" label="Title*"
:rules="requiredRules"
required required
/> />
</v-col> </v-col>
...@@ -123,6 +125,7 @@ ...@@ -123,6 +125,7 @@
item-text="name" item-text="name"
item-value="id" item-value="id"
label="Category" label="Category"
:rules="requiredRules"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -130,6 +133,7 @@ ...@@ -130,6 +133,7 @@
v-model="eContent" v-model="eContent"
label="Content" label="Content"
required required
:rules="requiredRules"
/> />
</v-col> </v-col>
<v-col <v-col
...@@ -141,6 +145,7 @@ ...@@ -141,6 +145,7 @@
item-text="name" item-text="name"
item-value="id" item-value="id"
label="Status" label="Status"
:rules="requiredRules"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -204,11 +209,13 @@ ...@@ -204,11 +209,13 @@
<v-divider class="mx-4" inset vertical /> <v-divider class="mx-4" inset vertical />
<v-spacer /> <v-spacer />
<v-toolbar-title> <v-toolbar-title>
<!-- modal-create -->
<v-dialog <v-dialog
v-model="dialog1" v-model="dialog1"
persistent persistent
max-width="600px" max-width="600px"
enctype="multipart/form-data" enctype="multipart/form-data"
lazy-validation
> >
<template #activator="{ on, attrs }"> <template #activator="{ on, attrs }">
<v-btn <v-btn
...@@ -235,6 +242,7 @@ ...@@ -235,6 +242,7 @@
<v-text-field <v-text-field
v-model="title" v-model="title"
label="Title*" label="Title*"
:rules="requiredRules"
required required
/> />
</v-col> </v-col>
...@@ -247,12 +255,14 @@ ...@@ -247,12 +255,14 @@
item-text="name" item-text="name"
item-value="id" item-value="id"
label="Category" label="Category"
:rules="requiredRules"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-textarea <v-textarea
v-model="content" v-model="content"
label="Content" label="Content"
:rules="requiredRules"
required required
/> />
</v-col> </v-col>
...@@ -265,6 +275,7 @@ ...@@ -265,6 +275,7 @@
item-text="name" item-text="name"
item-value="id" item-value="id"
label="Status" label="Status"
:rules="requiredRules"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -275,6 +286,7 @@ ...@@ -275,6 +286,7 @@
dense dense
accept="image/*" accept="image/*"
prepend-icon="mdi-camera" prepend-icon="mdi-camera"
:rules="requiredRules"
@change="fileSelected" @change="fileSelected"
/> />
</v-col> </v-col>
...@@ -428,7 +440,18 @@ export default { ...@@ -428,7 +440,18 @@ export default {
status: '', status: '',
created_at: '', created_at: '',
updated_at: '' updated_at: ''
} },
requiredRules: [
v => !!v || 'This field is required'
],
numberRules: [
v => !!v || 'This field is required',
v => v > 0 || 'value must be a positive integer'
],
imageRules: [
v => !!v || 'Images is required',
v => (v && v.length > 0) || 'Images is required'
]
} }
}, },
computed: { computed: {
...@@ -618,6 +641,7 @@ export default { ...@@ -618,6 +641,7 @@ export default {
this.eCategoryId = item.category_id this.eCategoryId = item.category_id
this.eContent = item.content this.eContent = item.content
this.eStatus = item.status this.eStatus = item.status
this.eImages = []
this.editedIndex = this.posts.indexOf(item) this.editedIndex = this.posts.indexOf(item)
console.log(this.editedIndex) console.log(this.editedIndex)
this.dialog = true this.dialog = true
...@@ -628,9 +652,10 @@ export default { ...@@ -628,9 +652,10 @@ export default {
fd.append('title', this.eTitle) fd.append('title', this.eTitle)
fd.append('category_id', this.eCategoryId) fd.append('category_id', this.eCategoryId)
fd.append('content', this.eContent) fd.append('content', this.eContent)
fd.append('images', this.eImages)
fd.append('status', this.eStatus) fd.append('status', this.eStatus)
if (typeof this.eImages !== 'string' && this.eImages != null) {
fd.append('images', this.eImages)
}
const currentPostIndex = this.editedIndex const currentPostIndex = this.editedIndex
this.$axios this.$axios
.post( .post(
......
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