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 >
3232<script >
3333
3434export 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