gancio-upstream/pages/recover/_code.vue

66 lines
1.7 KiB
Vue
Raw Normal View History

2020-01-24 00:50:50 +01:00
<template lang='pug'>
el-card.mt-5
h4(slot='header')
nuxt-link(to='/')
img(src='/favicon.ico')
2020-01-29 21:52:08 +01:00
span {{settings.title}} - {{$t('common.recover_password')}}
2019-05-30 12:12:51 +02:00
div(v-if='valid')
2019-10-22 23:48:15 +02:00
el-input(type='password', :placeholder='$t("common.new_password")' v-model='new_password' prefix-icon='el-icon-lock')
2019-05-30 12:12:51 +02:00
div(v-else) {{$t('recover.not_valid_code')}}
2019-09-11 19:12:24 +02:00
2020-01-24 00:50:50 +01:00
el-button.mt-2(plain v-if='valid' type="success" icon='el-icon-check'
@click='change_password') {{$t('common.send')}}
2019-05-30 12:12:51 +02:00
</template>
<script>
import { Message } from 'element-ui'
2020-01-24 00:50:50 +01:00
import { mapState } from 'vuex'
2019-05-30 12:12:51 +02:00
export default {
name: 'Recover',
2020-01-24 00:50:50 +01:00
layout: 'modal',
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 }
}
},
2020-01-24 00:50:50 +01:00
data () {
return { new_password: '' }
},
computed: mapState(['settings']),
2019-05-30 12:12:51 +02:00
methods: {
async change_password () {
try {
2019-10-28 17:33:20 +01:00
await this.$axios.$post('/user/recover_password', { recover_code: this.code, password: this.new_password })
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: 'success',
2019-07-03 17:50:53 +02:00
message: this.$t('common.password_updated')
2019-09-11 19:12:24 +02:00
})
2020-01-15 23:53:15 +01: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
})
}
}
2020-01-24 00:50:50 +01:00
},
head () {
return { title: `${this.settings.title} - Authorize` }
2019-05-30 12:12:51 +02:00
}
}
</script>
2020-01-24 00:50:50 +01:00
<style lang='less'>
h4 img {
max-height: 40px;
border-radius: 20px;
background-color: #333;
border: 1px solid #333;
}
</style>