Skip to content

Commit 6dcd141

Browse files
committed
rewrite resetPass with try catch for async
1 parent 668a0b8 commit 6dcd141

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/templates/Home/PasswordResetRequest.vue

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<template>
2-
<div data-test="password-reset-request">
2+
<div>
33
<p class="my-4">Please provide the email of the account to reset the password for:</p>
4-
<label>
5-
<b-form-input type="text" name="email" v-model="input.reset_email" placeholder="Email" data-test="reset-email" />
6-
</label>
7-
<b-button type="submit" v-on:click="resetPass()" variant="primary" data-test="reset-password-submit">Reset Password</b-button>
8-
<alert v-bind:message="alertMessage" v-bind:type="alertType"/>
4+
<form class="login-container" v-on:submit.prevent="resetPass" data-test="reset-password-submit">
5+
<label>
6+
<b-form-input type="text" name="email" v-model="input.reset_email" placeholder="Email" data-test="reset-email" required/>
7+
</label>
8+
<b-button type="submit" variant="primary">Reset Password</b-button>
9+
</form>
10+
<alert v-bind:message="alertMessage" v-bind:type="alertType" data-test="reset-password-alert"/>
911
</div>
1012
</template>
1113

@@ -34,22 +36,18 @@ export default {
3436
},
3537
3638
methods: {
37-
resetPass() {
39+
async resetPass() {
3840
if (this.input.reset_email !== "") {
39-
const response = postReset(this.input.reset_email)
40-
this.changeAlert("Sending", "warning")
41-
response
42-
.then(data => {
43-
if (data.status == 200) {
44-
this.changeAlert("Password reset email sent!", "success")
45-
46-
} else {
47-
this.changeAlert("Failed sending email", "warning")
48-
}
49-
})
50-
.catch(() => {
51-
this.changeAlert("Failed sending email", "warning")
52-
})
41+
try {
42+
this.changeAlert("Sending", "warning")
43+
const response = await postReset(this.input.reset_email)
44+
if (response.status != 200) {
45+
throw Error()
46+
}
47+
this.changeAlert("Password reset email sent!", "success")
48+
} catch {
49+
this.changeAlert("Failed sending email", "warning")
50+
}
5351
}
5452
},
5553
changeAlert(message, type) {

0 commit comments

Comments
 (0)