Skip to content

Commit 0b99e9e

Browse files
committed
skeleton for reset password routes contacting backend
1 parent cc0dd9f commit 0b99e9e

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

frontend/src/assets/css/tailwind.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117

118118
.auth-sub-container-error {
119119
@apply bg-red-500;
120-
@apply py-4;
120+
@apply p-4;
121121
@apply flex;
122122
@apply justify-center;
123123
@apply text-center;
@@ -166,6 +166,10 @@
166166
@apply mt-4;
167167
}
168168

169+
.auth-sub-container-content-submit-button:active, .auth-sub-container-content-submit-button:focus {
170+
outline: none;
171+
}
172+
169173
.auth-sub-container-content-button {
170174
@apply bg-purple-matcha;
171175
@apply w-full;

frontend/src/views/auth/ForgotPassword.vue

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<!-- eslint-disable max-len -->
33
<div class="auth-container">
4+
<div class="auth-sub-container-error mb-4" v-if="error.happened">
5+
<h1 class="auth-sub-container-error-message">{{error.message}}</h1>
6+
</div>
47
<div class="auth-sub-container">
58
<div class="auth-sub-container-content" v-if="!forgotPasswordEmailSent">
69
<img src="../../assets/auth/lock.png" class="h-12">
@@ -40,10 +43,32 @@ export default {
4043
email: '',
4144
},
4245
forgotPasswordEmailSent: false,
46+
error: {
47+
happened: false,
48+
message: '',
49+
},
4350
}),
4451
methods: {
45-
onSubmit() {
46-
this.forgotPasswordEmailSent = true;
52+
async onSubmit() {
53+
try {
54+
this.clearError();
55+
const passwordForgotResponse = await this.$http.post('/auth/password/forgot', this.formData);
56+
if (passwordForgotResponse.status !== 200) {
57+
this.displayError('Something went wrong on our end. We are sorry. Please, try again later.');
58+
return;
59+
}
60+
this.forgotPasswordEmailSent = true;
61+
} catch (error) {
62+
this.displayError('Something went wrong on our end. We are sorry. Please, try again later.');
63+
}
64+
},
65+
clearError() {
66+
this.error.message = '';
67+
this.error.happened = false;
68+
},
69+
displayError(message) {
70+
this.error.message = message;
71+
this.error.happened = true;
4772
},
4873
},
4974
};

frontend/src/views/auth/ResetPassword.vue

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
22
<!-- eslint-disable max-len -->
33
<div class="auth-container">
4+
<div class="auth-sub-container-error mb-4" v-if="error.happened">
5+
<h1 class="auth-sub-container-error-message">{{error.message}}</h1>
6+
</div>
47
<div class="auth-sub-container">
58
<div class="auth-sub-container-content" v-if="!passwordHasBeenReset">
69
<img src="../../assets/auth/refresh.png" class="h-12">
@@ -29,11 +32,18 @@
2932
<script>
3033
3134
export default {
35+
async beforeMount() {
36+
await this.checkToken();
37+
},
3238
data: () => ({
3339
formData: {
3440
password: '',
3541
},
3642
passwordHasBeenReset: false,
43+
error: {
44+
happened: false,
45+
message: '',
46+
},
3747
}),
3848
methods: {
3949
passwordErrorHandler(error) {
@@ -42,9 +52,26 @@ export default {
4252
}
4353
return 'This password is too easy to guess';
4454
},
45-
onSubmit() {
55+
async onSubmit() {
56+
const resetPasswordResponse = await this.$http.post('/auth/password/reset', this.formData);
57+
if (resetPasswordResponse.status !== 200) {
58+
this.error.message = resetPasswordResponse.data.error.message;
59+
this.error.happened = true;
60+
return;
61+
}
4662
this.passwordHasBeenReset = true;
4763
},
64+
async checkToken() {
65+
const { token } = this.$route.query;
66+
if (!token) {
67+
await this.$router.push('/accounts/password/reseterror');
68+
return;
69+
}
70+
const tokenCheck = await this.$http.post('/auth/password/check_token', { token });
71+
if (tokenCheck.status !== 200) {
72+
await this.$router.push('/accounts/password/reseterror');
73+
}
74+
},
4875
},
4976
};
5077

0 commit comments

Comments
 (0)