gancio-upstream/pages/recover/_code.vue

61 lines
1.6 KiB
Vue
Raw Normal View History

2020-01-24 00:50:50 +01:00
<template lang='pug'>
2020-07-28 12:24:39 +02:00
v-row.mt-5(align='center' justify='center')
v-col(cols='12' md="6" lg="5" xl="4")
v-card
v-card-title {{settings.title}} - {{$t('common.recover_password')}}
v-card-text
div(v-if='valid')
v-text-field(type='password'
2020-09-05 01:21:47 +02:00
:rules="$validators.password"
2020-07-28 12:24:39 +02:00
autofocus :placeholder='$t("common.new_password")'
v-model='new_password')
div(v-else) {{$t('recover.not_valid_code')}}
2019-09-11 19:12:24 +02:00
2020-07-28 12:24:39 +02:00
v-card-actions
2020-09-05 01:21:47 +02:00
v-spacer
2020-07-28 12:24:39 +02:00
v-btn(v-if='valid' color='primary' @click='change_password') {{$t('common.send')}}
2019-05-30 12:12:51 +02:00
</template>
<script>
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 () {
2020-09-05 01:21:47 +02:00
return { new_password: '' }
2020-01-24 00:50:50 +01:00
},
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 })
2020-10-07 11:12:13 +02:00
this.$root.$message('common.password_updated')
2020-01-15 23:53:15 +01:00
this.$router.replace('/login')
2019-09-11 19:12:24 +02:00
} catch (e) {
2020-10-07 11:12:13 +02:00
this.$root.$message(e, { color: 'warning' })
2019-05-30 12:12:51 +02:00
}
}
2020-01-24 00:50:50 +01:00
},
head () {
return { title: `${this.settings.title} - Authorize` }
2019-05-30 12:12:51 +02:00
}
}
</script>
<style>
2020-01-24 00:50:50 +01:00
h4 img {
max-height: 40px;
border-radius: 20px;
background-color: #333;
border: 1px solid #333;
}
</style>