Changeset View
Changeset View
Standalone View
Standalone View
src/resources/vue/PasswordReset.vue
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | export default { | ||||
}, | }, | ||||
created() { | created() { | ||||
// Verification code provided, auto-submit Step 2 | // Verification code provided, auto-submit Step 2 | ||||
if (this.$route.params.code) { | if (this.$route.params.code) { | ||||
if (/^([A-Z0-9]+)-([a-zA-Z0-9]+)$/.test(this.$route.params.code)) { | if (/^([A-Z0-9]+)-([a-zA-Z0-9]+)$/.test(this.$route.params.code)) { | ||||
this.short_code = RegExp.$1 | this.short_code = RegExp.$1 | ||||
this.code = RegExp.$2 | this.code = RegExp.$2 | ||||
this.submitStep2(true) | this.submitStep2(true) | ||||
} | } else { | ||||
else { | |||||
this.$root.errorPage(404) | this.$root.errorPage(404) | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
mounted() { | mounted() { | ||||
// Focus the first input (autofocus does not work when using the menu/router) | // Focus the first input (autofocus does not work when using the menu/router) | ||||
this.displayForm(1, true) | this.displayForm(1, true) | ||||
}, | }, | ||||
methods: { | methods: { | ||||
// Submits data to the API, validates and gets verification code | // Submits data to the API, validates and gets verification code | ||||
submitStep1() { | submitStep1() { | ||||
this.$root.clearFormValidation($('#step1 form')) | this.$root.clearFormValidation($('#step1 form')) | ||||
axios.post('/api/auth/password-reset/init', { | axios.post('/api/auth/password-reset/init', { | ||||
email: this.email | email: this.email | ||||
}).then(response => { | }).then(response => { | ||||
this.displayForm(2, true) | this.displayForm(2, true) | ||||
this.code = response.data.code | this.code = response.data.code | ||||
}) | }) | ||||
}, | }, | ||||
// Submits the code to the API for verification | // Submits the code to the API for verification | ||||
submitStep2(bylink) { | submitStep2(bylink) { | ||||
let post = { | |||||
code: this.code, | |||||
short_code: this.short_code | |||||
} | |||||
let params = {} | |||||
if (bylink === true) { | if (bylink === true) { | ||||
this.displayForm(2, false) | this.$root.startLoading() | ||||
params.ignoreErrors = true | |||||
} | } | ||||
this.$root.clearFormValidation($('#step2 form')) | this.$root.clearFormValidation($('#step2 form')) | ||||
axios.post('/api/auth/password-reset/verify', { | axios.post('/api/auth/password-reset/verify', post, params).then(response => { | ||||
code: this.code, | this.$root.stopLoading() | ||||
short_code: this.short_code | |||||
}).then(response => { | |||||
this.userId = response.data.userId | this.userId = response.data.userId | ||||
this.displayForm(3, true) | this.displayForm(3, true) | ||||
}).catch(error => { | }).catch(error => { | ||||
if (bylink === true) { | if (bylink === true) { | ||||
// FIXME: display step 1, user can do nothing about it anyway | this.$root.stopLoading() | ||||
// Maybe we should display 404 error page? | this.$root.errorPage(404, '', this.$t('password.link-invalid')) | ||||
this.displayForm(1, true) | |||||
} | } | ||||
}) | }) | ||||
}, | }, | ||||
// Submits the data to the API to reset the password | // Submits the data to the API to reset the password | ||||
submitStep3() { | submitStep3() { | ||||
this.$root.clearFormValidation($('#step3 form')) | this.$root.clearFormValidation($('#step3 form')) | ||||
axios.post('/api/auth/password-reset', { | axios.post('/api/auth/password-reset', { | ||||
Show All 33 Lines |