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

Merge branch 'dev' into 'feature/UI-vuetify'

# Conflicts:
#   pages/login.vue
#   plugins/axios.js
parents fdd32d6c 205c8dde
...@@ -81,22 +81,26 @@ ...@@ -81,22 +81,26 @@
<script> <script>
export default { export default {
methods: { methods: {
logout () { async logout () {
fetch('http://127.0.0.1:8000/api/logout', { try {
method: 'POST', const resp = await this.$axios.post('/logout', {
headers: {
'Content-Type': 'application/json',
accept: 'application/json'
},
body: JSON.stringify({
token: this.$auth.$storage.getUniversal('token') token: this.$auth.$storage.getUniversal('token')
}) })
}) if (resp.status == '200') {
localStorage.setItem('token', '') this.$toast.success('Logout!', {
this.$auth.$storage.setUniversal('loggedIn', 'false') duration: 2000
this.$auth.$storage.setUniversal('token', '') })
this.$auth.$storage.setUniversal('userName', '') this.$router.push('/login')
this.$router.push('/login') localStorage.setItem('token', '')
this.$auth.$storage.setUniversal('loggedIn', 'false')
this.$auth.$storage.setUniversal('token', '')
this.$auth.$storage.setUniversal('userName', '')
}
} catch (e) {
this.$toast.error('ERR !', {
duration: 2000
})
}
} }
} }
} }
......
...@@ -109,15 +109,10 @@ export default { ...@@ -109,15 +109,10 @@ export default {
this.password = '' this.password = ''
this.checkbox = false this.checkbox = false
}, },
async login () { async login() {
try { try {
const resp = await fetch('http://127.0.0.1:8000/api/login', { const resp = await this.$axios.post('/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
...@@ -137,13 +132,13 @@ export default { ...@@ -137,13 +132,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>
......
export default function ({ $axios }, inject, redirect ) { export default function ({ $axios }, inject, redirect) {
$axios.onError((error) => { $axios.onError((error) => {
if (error.response.status === 500) { if (error.response.status === 500) {
redirect('/500') redirect('/500')
...@@ -15,7 +15,8 @@ export default function ({ $axios }, inject, redirect ) { ...@@ -15,7 +15,8 @@ export default function ({ $axios }, inject, redirect ) {
const api = $axios.create({ const api = $axios.create({
headers: { headers: {
common: { common: {
Accept: 'application/json, text/plain, */*' Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json, text/plain, */*'
} }
} }
}) })
......
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