yandere_fe/src/components/password_reset/password_reset.js

72 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-05 04:23:28 -07:00
import { mapState } from 'vuex'
import passwordResetApi from '../../services/new_api/password_reset.js'
2020-10-20 11:18:23 -07:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faTimes
} from '@fortawesome/free-solid-svg-icons'
library.add(
faTimes
)
2019-09-05 04:23:28 -07:00
const passwordReset = {
data: () => ({
user: {
email: ''
},
isPending: false,
success: false,
throttled: false,
error: null
}),
computed: {
...mapState({
signedIn: (state) => !!state.users.currentUser,
instance: state => state.instance
}),
mailerEnabled () {
return this.instance.mailerEnabled
}
},
created () {
if (this.signedIn) {
this.$router.push({ name: 'root' })
}
},
2019-10-16 03:00:26 -07:00
props: {
passwordResetRequested: {
default: false,
type: Boolean
}
},
2019-09-05 04:23:28 -07:00
methods: {
dismissError () {
this.error = null
},
submit () {
this.isPending = true
const email = this.user.email
const instance = this.instance.server
passwordResetApi({ instance, email }).then(({ status }) => {
this.isPending = false
this.user.email = ''
if (status === 204) {
this.success = true
this.error = null
} else if (status === 429) {
this.throttled = true
this.error = this.$t('password_reset.too_many_requests')
}
}).catch(() => {
this.isPending = false
this.user.email = ''
this.error = this.$t('general.generic_error')
})
}
}
}
export default passwordReset