| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container fill-height fluid class="d-flex justify-center align-center"> | 
					
						
							|  |  |  |     <v-card color="background d-flex flex-column align-center" flat width="600px"> | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |       <v-card-title class="headline justify-center"> {{ $t('user.forgot-password') }} </v-card-title> | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |       <BaseDivider /> | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <v-form @submit.prevent="requestLink()"> | 
					
						
							|  |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-model="email" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             autofocus | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             name="login" | 
					
						
							|  |  |  |             :label="$t('user.email')" | 
					
						
							|  |  |  |             type="text" | 
					
						
							|  |  |  |           /> | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |           <p class="text-center">{{ $t('user.forgot-password-text') }}</p> | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |           <v-card-actions class="justify-center"> | 
					
						
							|  |  |  |             <div class="max-button"> | 
					
						
							|  |  |  |               <v-btn :loading="loading" color="primary" type="submit" large rounded class="rounded-xl" block> | 
					
						
							|  |  |  |                 <v-icon left> | 
					
						
							|  |  |  |                   {{ $globals.icons.email }} | 
					
						
							|  |  |  |                 </v-icon> | 
					
						
							|  |  |  |                 {{ $t("user.reset-password") }} | 
					
						
							|  |  |  |               </v-btn> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </v-card-actions> | 
					
						
							|  |  |  |         </v-form> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |       <v-btn class="mx-auto" text nuxt to="/login"> {{ $t("user.login") }} </v-btn> | 
					
						
							|  |  |  |     </v-card> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  | import { defineComponent, toRefs, reactive, useContext } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  | import { alert } from "~/composables/use-toast"; | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   layout: "basic", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   setup() { | 
					
						
							|  |  |  |     const state = reactive({ | 
					
						
							|  |  |  |       email: "", | 
					
						
							|  |  |  |       loading: false, | 
					
						
							|  |  |  |       error: false, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |     const { i18n } = useContext(); | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const api = useUserApi(); | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async function requestLink() { | 
					
						
							|  |  |  |       state.loading = true; | 
					
						
							|  |  |  |       // TODO: Fix Response to send meaningful error
 | 
					
						
							|  |  |  |       const { response } = await api.email.sendForgotPassword({ email: state.email }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (response?.status === 200) { | 
					
						
							|  |  |  |         state.loading = false; | 
					
						
							|  |  |  |         state.error = false; | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |         alert.success(i18n.tc("profile.email-sent")); | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         state.loading = false; | 
					
						
							|  |  |  |         state.error = true; | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |         alert.error(i18n.tc("profile.error-sending-email")); | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       requestLink, | 
					
						
							|  |  |  |       ...toRefs(state), | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |       title: this.$tc("user.login"), | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style lang="css"> | 
					
						
							|  |  |  | .max-button { | 
					
						
							|  |  |  |   width: 300px; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  | </style> |