Skip to content

Commit 734c382

Browse files
committed
232: forgot and reset password
1 parent 0b99e9e commit 734c382

File tree

6 files changed

+52
-25
lines changed

6 files changed

+52
-25
lines changed

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
MYSQL_ROOT_PASSWORD: root
1212
MYSQL_DATABASE: pymatcha
1313
env_file:
14-
- .env
14+
- .env.docker
1515
volumes:
1616
- mysql:/var/lib/mysql
1717
networks:
@@ -40,7 +40,7 @@ services:
4040
context: .
4141
dockerfile: backend.Dockerfile
4242
env_file:
43-
- .env
43+
- .env.docker
4444
entrypoint: celery worker --workdir . -A PyMatcha.celery -B --loglevel=info
4545
volumes:
4646
- backend:/backend
@@ -61,7 +61,7 @@ services:
6161
context: .
6262
dockerfile: backend.Dockerfile
6363
env_file:
64-
- .env
64+
- .env.docker
6565
ports:
6666
- "8080:5000"
6767
volumes:

frontend/src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue';
22
import { ValidationProvider, ValidationObserver, extend } from 'vee-validate/dist/vee-validate.full.esm';
33
import http from './plugins/http';
4+
import errorMessenger from './plugins/errorMessenger';
45
import App from './App.vue';
56
import router from './router';
67
import store from './store';
@@ -14,6 +15,7 @@ extend('validPassword', validPassword);
1415
Vue.config.productionTip = false;
1516

1617
Vue.use(http);
18+
Vue.use(errorMessenger);
1719

1820
new Vue({
1921
router,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Vue from 'vue';
2+
3+
export default {
4+
install() {
5+
Vue.prototype.$errorMessenger = (error) => {
6+
if (error.response && error.response.status === 404) {
7+
return 'Something went wrong on our end. We will fix it soon. Please, try again later';
8+
}
9+
return error.response.data.error.message;
10+
};
11+
},
12+
};

frontend/src/plugins/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function createAxiosInstance(baseURL) {
1111
});
1212
}
1313

14-
const axiosInstance = createAxiosInstance('http://localhost:8080');
14+
const axiosInstance = createAxiosInstance(process.env.VUE_APP_BACKEND_BASE_URL);
1515

1616
export default {
1717
install() {

frontend/src/views/auth/ForgotPassword.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,15 @@ export default {
5252
async onSubmit() {
5353
try {
5454
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-
}
55+
await this.sendResetPasswordLink();
6056
this.forgotPasswordEmailSent = true;
6157
} catch (error) {
62-
this.displayError('Something went wrong on our end. We are sorry. Please, try again later.');
58+
this.displayError(this.$errorMessenger(error));
6359
}
6460
},
61+
async sendResetPasswordLink() {
62+
await this.$http.post('/auth/password/forgot', this.formData);
63+
},
6564
clearError() {
6665
this.error.message = '';
6766
this.error.happened = false;

frontend/src/views/auth/ResetPassword.vue

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="auth-sub-container-error mb-4" v-if="error.happened">
55
<h1 class="auth-sub-container-error-message">{{error.message}}</h1>
66
</div>
7-
<div class="auth-sub-container">
7+
<div class="auth-sub-container" v-if="!error.happened">
88
<div class="auth-sub-container-content" v-if="!passwordHasBeenReset">
99
<img src="../../assets/auth/refresh.png" class="h-12">
1010
<h1 class="auth-sub-container-content-heading">Enter your new password</h1>
@@ -32,7 +32,7 @@
3232
<script>
3333
3434
export default {
35-
async beforeMount() {
35+
async created() {
3636
await this.checkToken();
3737
},
3838
data: () => ({
@@ -53,25 +53,39 @@ export default {
5353
return 'This password is too easy to guess';
5454
},
5555
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;
56+
try {
57+
this.clearError();
58+
await this.resetPassword();
59+
this.passwordHasBeenReset = true;
60+
} catch (error) {
61+
this.displayError(this.$errorMessenger(error));
6162
}
62-
this.passwordHasBeenReset = true;
6363
},
6464
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) {
65+
try {
66+
const { token } = this.$route.query;
67+
if (!token) {
68+
await this.$router.push('/accounts/password/reseterror');
69+
return;
70+
}
71+
await this.$http.post('/auth/password/check_token', { token });
72+
} catch (error) {
7273
await this.$router.push('/accounts/password/reseterror');
7374
}
7475
},
76+
async resetPassword() {
77+
const { password } = this.formData;
78+
const { token } = this.$route.query;
79+
await this.$http.post('/auth/password/reset', { password, token });
80+
},
81+
clearError() {
82+
this.error.message = '';
83+
this.error.happened = false;
84+
},
85+
displayError(message) {
86+
this.error.message = message;
87+
this.error.happened = true;
88+
},
7589
},
7690
};
7791

0 commit comments

Comments
 (0)