| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container fill-height fluid class="d-flex justify-center align-start narrow-container"> | 
					
						
							|  |  |  |     <v-card color="background d-flex flex-column align-center" flat width="700px"> | 
					
						
							|  |  |  |       <v-card-title class="headline"> User Registration </v-card-title> | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <v-form ref="domRegisterForm" @submit.prevent="register()"> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |           <div class="d-flex justify-center my-2"> | 
					
						
							|  |  |  |             <v-btn-toggle v-model="joinGroup" mandatory tile group color="primary"> | 
					
						
							|  |  |  |               <v-btn :value="false" small @click="joinGroup = false"> Create a Group </v-btn> | 
					
						
							|  |  |  |               <v-btn :value="true" small @click="joinGroup = true"> Join a Group </v-btn> | 
					
						
							|  |  |  |             </v-btn-toggle> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-if="!joinGroup" | 
					
						
							|  |  |  |             v-model="form.group" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             autofocus | 
					
						
							|  |  |  |             validate-on-blur | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             :prepend-icon="$globals.icons.group" | 
					
						
							|  |  |  |             :rules="[tokenOrGroup]" | 
					
						
							|  |  |  |             label="New Group Name" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-else | 
					
						
							|  |  |  |             v-model="form.groupToken" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             validate-on-blur | 
					
						
							|  |  |  |             :rules="[tokenOrGroup]" | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             :prepend-icon="$globals.icons.group" | 
					
						
							|  |  |  |             label="Group Token" | 
					
						
							|  |  |  |           /> | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-model="form.email" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             validate-on-blur | 
					
						
							|  |  |  |             :prepend-icon="$globals.icons.email" | 
					
						
							|  |  |  |             label="Email" | 
					
						
							|  |  |  |             :rules="[validators.required, validators.email]" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-model="form.username" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             :prepend-icon="$globals.icons.user" | 
					
						
							|  |  |  |             label="Username" | 
					
						
							|  |  |  |             :rules="[validators.required]" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-model="form.password" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             :prepend-icon="$globals.icons.lock" | 
					
						
							|  |  |  |             name="password" | 
					
						
							|  |  |  |             label="Password" | 
					
						
							|  |  |  |             type="password" | 
					
						
							|  |  |  |             :rules="[validators.required]" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           <v-text-field | 
					
						
							|  |  |  |             v-model="form.passwordConfirm" | 
					
						
							|  |  |  |             filled | 
					
						
							|  |  |  |             rounded | 
					
						
							|  |  |  |             validate-on-blur | 
					
						
							|  |  |  |             class="rounded-lg" | 
					
						
							|  |  |  |             :prepend-icon="$globals.icons.lock" | 
					
						
							|  |  |  |             name="password" | 
					
						
							|  |  |  |             label="Confirm Password" | 
					
						
							|  |  |  |             type="password" | 
					
						
							|  |  |  |             :rules="[validators.required, passwordMatch]" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           <div class="mt-n4 px-8"> | 
					
						
							|  |  |  |             <v-checkbox v-model="form.private" label="Keep My Recipes Private"></v-checkbox> | 
					
						
							|  |  |  |             <p class="text-caption mt-n4"> | 
					
						
							|  |  |  |               Sets your group and all recipes defaults to private. You can always change this later. | 
					
						
							|  |  |  |             </p> | 
					
						
							|  |  |  |             <v-checkbox v-model="form.advanced" label="Enable Advanced Content"></v-checkbox> | 
					
						
							|  |  |  |             <p class="text-caption mt-n4"> | 
					
						
							|  |  |  |               Enables advanced features like Recipe Scaling, API keys, Webhooks, and Data Management. Don't worry, you | 
					
						
							|  |  |  |               can always change this later | 
					
						
							|  |  |  |             </p> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <div class="d-flex flex-column justify-center"> | 
					
						
							|  |  |  |             <v-btn :loading="loggingIn" color="primary" type="submit" large rounded class="rounded-xl" block> | 
					
						
							|  |  |  |               Register | 
					
						
							|  |  |  |             </v-btn> | 
					
						
							|  |  |  |             <v-btn class="mx-auto my-2" text to="/login"> Login </v-btn> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </v-form> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </v-card> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | import { computed, defineComponent, reactive, toRefs, ref, useRouter, watch } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | import { validators } from "@/composables/use-validators"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | import { alert } from "~/composables/use-toast"; | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | import { useRouterQuery } from "@/composables/use-router"; | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   layout: "basic", | 
					
						
							|  |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const api = useUserApi(); | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |     const state = reactive({ | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       joinGroup: false, | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |       loggingIn: false, | 
					
						
							|  |  |  |       success: false, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     const allowSignup = computed(() => process.env.AllOW_SIGNUP); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |     const token = useRouterQuery("token"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     watch(token, (newToken) => { | 
					
						
							|  |  |  |       if (newToken) { | 
					
						
							|  |  |  |         form.groupToken = newToken; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (token) { | 
					
						
							|  |  |  |       state.joinGroup = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // @ts-ignore
 | 
					
						
							|  |  |  |     const domRegisterForm = ref<VForm>(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const form = reactive({ | 
					
						
							|  |  |  |       group: "", | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       groupToken: token, | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |       email: "", | 
					
						
							|  |  |  |       username: "", | 
					
						
							|  |  |  |       password: "", | 
					
						
							|  |  |  |       passwordConfirm: "", | 
					
						
							|  |  |  |       advanced: false, | 
					
						
							|  |  |  |       private: false, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const passwordMatch = () => form.password === form.passwordConfirm || "Passwords do not match"; | 
					
						
							|  |  |  |     const tokenOrGroup = () => form.group !== "" || form.groupToken !== "" || "Group name or token must be given"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |     const router = useRouter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |     async function register() { | 
					
						
							|  |  |  |       if (!domRegisterForm.value?.validate()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       const { response } = await api.register.register(form); | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (response?.status === 201) { | 
					
						
							|  |  |  |         state.success = true; | 
					
						
							|  |  |  |         alert.success("Registration Success"); | 
					
						
							| 
									
										
										
										
											2021-10-04 20:16:37 -08:00
										 |  |  |         router.push("/login"); | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       token, | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |       domRegisterForm, | 
					
						
							|  |  |  |       validators, | 
					
						
							|  |  |  |       allowSignup, | 
					
						
							|  |  |  |       form, | 
					
						
							|  |  |  |       ...toRefs(state), | 
					
						
							|  |  |  |       passwordMatch, | 
					
						
							|  |  |  |       tokenOrGroup, | 
					
						
							|  |  |  |       register, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       title: this.$t("user.register") as string, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |