gancio/pages/recover/_code.vue

54 lines
1.4 KiB
Vue
Raw Normal View History

2019-05-30 12:12:51 +02:00
<template lang="pug">
2019-06-08 13:18:47 +02:00
el-card
nuxt-link.float-right(to='/')
el-button(circle icon='el-icon-close' type='danger' size='small' plain)
h5 <img src='/favicon.ico'/> {{$t('common.recover_password')}}
2019-05-30 12:12:51 +02:00
div(v-if='valid')
el-form
el-form-item {{$t('common.new_password')}}
el-input(type='password', v-model='new_password')
el-button(plain type="success" icon='el-icon-send', @click='change_password') {{$t('common.send')}}
div(v-else) {{$t('recover.not_valid_code')}}
2019-09-11 19:12:24 +02:00
2019-05-30 12:12:51 +02:00
</template>
<script>
import { Message } from 'element-ui'
export default {
name: 'Recover',
data () {
return { new_password: '' }
},
2019-09-11 19:12:24 +02:00
async asyncData ({ params, $axios }) {
2019-05-30 12:12:51 +02:00
const code = params.code
try {
const valid = await $axios.$post('/user/check_recover_code', { recover_code: code })
return { valid, code }
2019-09-11 19:12:24 +02:00
} catch (e) {
2019-05-30 12:12:51 +02:00
return { valid: false }
}
},
methods: {
async change_password () {
try {
const res = await this.$axios.$post('/user/recover_password', { recover_code: this.code, password: this.new_password })
Message({
2019-06-25 01:05:38 +02:00
showClose: true,
2019-05-30 12:12:51 +02:00
type: 'success',
2019-07-03 17:50:53 +02:00
message: this.$t('common.password_updated')
2019-09-11 19:12:24 +02:00
})
2019-07-03 17:50:53 +02:00
this.$router.replace('/login')
2019-09-11 19:12:24 +02:00
} catch (e) {
2019-05-30 12:12:51 +02:00
Message({
2019-06-25 01:05:38 +02:00
showClose: true,
2019-05-30 12:12:51 +02:00
type: 'warning',
message: e
})
}
}
}
}
</script>