gancio-upstream/pages/settings.vue

57 lines
1.6 KiB
Vue
Raw Normal View History

2019-04-26 23:14:43 +02:00
<template lang="pug">
2019-06-07 17:02:33 +02:00
el-card
nuxt-link.float-right(to='/')
2019-06-10 01:25:05 +02:00
el-button
v-icon(name='times' color='red')
2019-06-07 17:02:33 +02:00
h5 {{$t('common.settings')}}
el-form(action='/api/user' method='PUT' @submit.native.prevent='change_password')
el-form-item {{$t('settings.change_password')}}
el-input(v-model='password' type='password')
el-button(type='success' native-type='submit') {{$t('common.send')}}
el-divider {{$t('settings.danger_section')}}
p {{$t('settings.remove_account')}}
el-button(type='danger' @click='remove_account') {{$t('common.remove')}}
2019-04-26 23:14:43 +02:00
</template>
<script>
import { mapState, mapActions } from 'vuex'
import { Message, MessageBox } from 'element-ui'
2019-04-26 23:14:43 +02:00
export default {
data () {
return {
password: '',
}
},
async asyncData ({ $axios, params }) {
const user = await $axios.$get('/auth/user')
user.mastodon_auth = ''
return { user }
},
2019-04-26 23:14:43 +02:00
methods: {
async change_password () {
2019-05-30 12:04:14 +02:00
if (!this.password) return
2019-06-07 17:02:33 +02:00
const user_data = { id : this.$auth.user.id, password: this.password }
2019-05-30 12:04:14 +02:00
try {
2019-06-07 17:02:33 +02:00
const user = await this.$axios.$put('/user', user_data)
Message({ message: this.$t('settings.password_updated'), type: 'success' })
this.$router.replace('/')
2019-05-30 12:04:14 +02:00
} catch (e) {
console.log(e)
}
},
async remove_account () {
MessageBox.confirm(this.$t('settings.remove_account_confirm'), this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'),
type: 'error'
}).then( () => {
this.$axios.$delete('/user')
})
}
2019-04-26 23:14:43 +02:00
}
}
</script>