|
3 | 3 | <v-col cols="12" sm="8" md="4"> |
4 | 4 | <v-card flat class="mt-12"> |
5 | 5 | <v-toolbar color="secondary" dark flat> |
6 | | - <v-toolbar-title>Reset password form</v-toolbar-title> |
| 6 | + <v-toolbar-title>Password reset form</v-toolbar-title> |
7 | 7 | </v-toolbar> |
8 | 8 | <v-form @submit.prevent="validate" ref="form"> |
9 | 9 | <v-card-text> |
10 | 10 | <p> |
11 | | - Did you forget your password? Enter your parent's e-mail address |
12 | | - below. They entered this when they created your account. |
| 11 | + Create a new password. |
13 | 12 | </p> |
| 13 | + |
| 14 | + <v-text-field |
| 15 | + v-bind="fields.password" |
| 16 | + v-model="fields.password.value" |
| 17 | + :disabled="isSubmitting" |
| 18 | + /> |
14 | 19 | <v-text-field |
15 | | - v-bind="fields.username" |
16 | | - v-model="fields.username.value" |
| 20 | + v-bind="fields.passwordConfirm" |
| 21 | + v-model="fields.passwordConfirm.value" |
17 | 22 | :disabled="isSubmitting" |
18 | 23 | /> |
19 | 24 | </v-card-text> |
20 | 25 |
|
21 | 26 | <v-card-actions> |
22 | 27 | <v-spacer /> |
23 | 28 | <v-btn color="secondary" type="submit" dark :disabled="isSubmitting" |
24 | | - >Send Reset Password Request</v-btn |
| 29 | + >Reset Password</v-btn |
25 | 30 | > |
26 | 31 | </v-card-actions> |
27 | 32 | </v-form> |
|
31 | 36 | </template> |
32 | 37 |
|
33 | 38 | <script> |
34 | | -export default { |
35 | | - name: "reset-password", |
36 | | - methods: { |
37 | | - async submit() { |
38 | | - this.$store.dispatch( |
39 | | - "Snackbar/showError", |
40 | | - "This feature not yet implemented" |
41 | | - ); |
42 | | - }, |
43 | | - validate() { |
44 | | - if (this.$refs.form.validate()) { |
45 | | - this.submit(); |
| 39 | + import {auth} from "@/api"; |
| 40 | +
|
| 41 | + export default { |
| 42 | + name: "reset-password", |
| 43 | + created() { |
| 44 | + if (! this.$route.params.token) { |
| 45 | + this.$store.dispatch( |
| 46 | + "Snackbar/showError", |
| 47 | + "Missing token from URL. Password cannot be reset." |
| 48 | + ); |
| 49 | + this.$router.push({ name: "forgot-password" }); |
46 | 50 | } |
47 | | - } |
48 | | - }, |
49 | | - data() { |
50 | | - return { |
51 | | - isSubmitting: false, |
52 | | - fields: { |
53 | | - username: { |
54 | | - label: "Parents E-mail", |
55 | | - type: "email", |
56 | | - rules: [v => !!v || "Please provide a valid e-mail address"] |
| 51 | + }, |
| 52 | + methods: { |
| 53 | + async submit() { |
| 54 | + try { |
| 55 | + await auth.resetPassword(this.$route.params.token, this.fields.password.value); |
| 56 | + this.$store.dispatch( |
| 57 | + "Snackbar/showInfo", |
| 58 | + "Password reset successfully. You may now login." |
| 59 | + ); |
| 60 | + this.$router.push({ name: "login" }) |
| 61 | + } catch (e) { |
| 62 | + console.error(e); |
| 63 | + this.$store.dispatch( |
| 64 | + "Snackbar/showError", |
| 65 | + "Request failed" |
| 66 | + ); |
| 67 | + } |
| 68 | + }, |
| 69 | + validate() { |
| 70 | + if (this.$refs.form.validate()) { |
| 71 | + this.submit(); |
57 | 72 | } |
58 | 73 | } |
59 | | - }; |
60 | | - } |
61 | | -}; |
| 74 | + }, |
| 75 | + data() { |
| 76 | + return { |
| 77 | + isSubmitting: false, |
| 78 | + fields: { |
| 79 | + password: { |
| 80 | + label: "Password", |
| 81 | + type: "password", |
| 82 | + autocomplete: "new-password", |
| 83 | + value: "", |
| 84 | + rules: [ |
| 85 | + v => !!v || "Don't forget to give a password", |
| 86 | + v => v.length >= 8 || "Password must be at least 8 characters" |
| 87 | + ] |
| 88 | + }, |
| 89 | + passwordConfirm: { |
| 90 | + label: "Confirm Password", |
| 91 | + type: "password", |
| 92 | + value: "", |
| 93 | + rules: [ |
| 94 | + v => v == this.fields.password.value || "Passwords do not match" |
| 95 | + ] |
| 96 | + }, |
| 97 | + } |
| 98 | + }; |
| 99 | + } |
| 100 | + }; |
62 | 101 | </script> |
0 commit comments