| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container class="narrow-container"> | 
					
						
							|  |  |  |     <BasePageTitle divider> | 
					
						
							|  |  |  |       <template #header> | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |         <div class="d-flex flex-column align-center justify-center"> | 
					
						
							|  |  |  |           <UserAvatar size="96" :user-id="$auth.user.id" /> | 
					
						
							|  |  |  |           <AppButtonUpload | 
					
						
							|  |  |  |             class="my-1" | 
					
						
							|  |  |  |             file-name="profile" | 
					
						
							|  |  |  |             accept="image/*" | 
					
						
							|  |  |  |             :url="`/api/users/${$auth.user.id}/image`" | 
					
						
							|  |  |  |             @uploaded="$auth.fetchUser()" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |       </template> | 
					
						
							|  |  |  |       <template #title> Your Profile Settings </template> | 
					
						
							|  |  |  |     </BasePageTitle> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |     <section class="mt-5"> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |       <ToggleState tag="article"> | 
					
						
							|  |  |  |         <template #activator="{ toggle, state }"> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |           <v-btn v-if="!state" color="info" class="mt-2 mb-n3" @click="toggle"> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |             <v-icon left>{{ $globals.icons.lock }}</v-icon> | 
					
						
							|  |  |  |             {{ $t("settings.change-password") }} | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |           <v-btn v-else color="info" class="mt-2 mb-n3" @click="toggle"> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |             <v-icon left>{{ $globals.icons.user }}</v-icon> | 
					
						
							|  |  |  |             {{ $t("settings.profile") }} | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							|  |  |  |         </template> | 
					
						
							|  |  |  |         <template #default="{ state }"> | 
					
						
							| 
									
										
										
										
											2021-10-19 18:45:03 -08:00
										 |  |  |           <v-slide-x-transition leave-absolute hide-on-leave> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |             <div v-if="!state" key="personal-info"> | 
					
						
							|  |  |  |               <BaseCardSectionTitle class="mt-10" title="Personal Information"> </BaseCardSectionTitle> | 
					
						
							|  |  |  |               <v-card tag="article" outlined> | 
					
						
							|  |  |  |                 <v-card-text class="pb-0"> | 
					
						
							|  |  |  |                   <v-form ref="userUpdate"> | 
					
						
							|  |  |  |                     <v-text-field v-model="userCopy.username" :label="$t('user.username')" required validate-on-blur> | 
					
						
							|  |  |  |                     </v-text-field> | 
					
						
							|  |  |  |                     <v-text-field v-model="userCopy.fullName" :label="$t('user.full-name')" required validate-on-blur> | 
					
						
							|  |  |  |                     </v-text-field> | 
					
						
							|  |  |  |                     <v-text-field v-model="userCopy.email" :label="$t('user.email')" validate-on-blur required> | 
					
						
							|  |  |  |                     </v-text-field> | 
					
						
							|  |  |  |                   </v-form> | 
					
						
							|  |  |  |                 </v-card-text> | 
					
						
							|  |  |  |                 <v-card-actions> | 
					
						
							|  |  |  |                   <v-spacer></v-spacer> | 
					
						
							|  |  |  |                   <BaseButton update @click="updateUser" /> | 
					
						
							|  |  |  |                 </v-card-actions> | 
					
						
							|  |  |  |               </v-card> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |             <div v-if="state" key="change-password"> | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |               <BaseCardSectionTitle class="mt-10" :title="$tc('settings.change-password')"> </BaseCardSectionTitle> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |               <v-card outlined> | 
					
						
							|  |  |  |                 <v-card-text class="pb-0"> | 
					
						
							|  |  |  |                   <v-form ref="passChange"> | 
					
						
							|  |  |  |                     <v-text-field | 
					
						
							|  |  |  |                       v-model="password.current" | 
					
						
							|  |  |  |                       :prepend-icon="$globals.icons.lock" | 
					
						
							|  |  |  |                       :label="$t('user.current-password')" | 
					
						
							|  |  |  |                       validate-on-blur | 
					
						
							|  |  |  |                       :type="showPassword ? 'text' : 'password'" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       :append-icon="showPassword ? $globals.icons.eye : $globals.icons.eyeOff" | 
					
						
							|  |  |  |                       @click:append="showPassword = !showPassword" | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                     ></v-text-field> | 
					
						
							|  |  |  |                     <v-text-field | 
					
						
							|  |  |  |                       v-model="password.newOne" | 
					
						
							|  |  |  |                       :prepend-icon="$globals.icons.lock" | 
					
						
							|  |  |  |                       :label="$t('user.new-password')" | 
					
						
							|  |  |  |                       :type="showPassword ? 'text' : 'password'" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       :append-icon="showPassword ? $globals.icons.eye : $globals.icons.eyeOff" | 
					
						
							|  |  |  |                       @click:append="showPassword = !showPassword" | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                     ></v-text-field> | 
					
						
							|  |  |  |                     <v-text-field | 
					
						
							|  |  |  |                       v-model="password.newTwo" | 
					
						
							|  |  |  |                       :prepend-icon="$globals.icons.lock" | 
					
						
							|  |  |  |                       :label="$t('user.confirm-password')" | 
					
						
							|  |  |  |                       :rules="[password.newOne === password.newTwo || $t('user.password-must-match')]" | 
					
						
							|  |  |  |                       validate-on-blur | 
					
						
							|  |  |  |                       :type="showPassword ? 'text' : 'password'" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       :append-icon="showPassword ? $globals.icons.eye : $globals.icons.eyeOff" | 
					
						
							|  |  |  |                       @click:append="showPassword = !showPassword" | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                     ></v-text-field> | 
					
						
							|  |  |  |                   </v-form> | 
					
						
							|  |  |  |                 </v-card-text> | 
					
						
							|  |  |  |                 <v-card-actions> | 
					
						
							|  |  |  |                   <v-spacer></v-spacer> | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                   <BaseButton | 
					
						
							|  |  |  |                     update | 
					
						
							|  |  |  |                     :disabled="!passwordsMatch || password.current.length < 0" | 
					
						
							|  |  |  |                     @click="updatePassword" | 
					
						
							|  |  |  |                   /> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                 </v-card-actions> | 
					
						
							|  |  |  |               </v-card> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </v-slide-x-transition> | 
					
						
							|  |  |  |         </template> | 
					
						
							|  |  |  |       </ToggleState> | 
					
						
							|  |  |  |     </section> | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |     <section> | 
					
						
							|  |  |  |       <BaseCardSectionTitle class="mt-10" title="Preferences"> </BaseCardSectionTitle> | 
					
						
							|  |  |  |       <v-checkbox | 
					
						
							|  |  |  |         v-model="userCopy.advanced" | 
					
						
							|  |  |  |         class="mt-n4" | 
					
						
							|  |  |  |         label="Show advanced features (API Keys, Webhooks, and Data Management)" | 
					
						
							|  |  |  |         @change="updateUser" | 
					
						
							|  |  |  |       ></v-checkbox> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       <div class="d-flex flex-wrap justify-center mt-5"> | 
					
						
							|  |  |  |         <v-btn outlined class="rounded-xl my-1 mx-1" to="/user/profile" nuxt exact> | 
					
						
							|  |  |  |           <v-icon left> | 
					
						
							|  |  |  |             {{ $globals.icons.backArrow }} | 
					
						
							|  |  |  |           </v-icon> | 
					
						
							|  |  |  |           Back to Profile | 
					
						
							|  |  |  |         </v-btn> | 
					
						
							| 
									
										
										
										
											2022-03-23 04:54:16 +01:00
										 |  |  |         <v-btn outlined class="rounded-xl my-1 mx-1" to="/group"> Looking for Privacy Settings? </v-btn> | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     </section> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  | import { ref, reactive, defineComponent, computed, useContext, watch, toRefs } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  | import UserAvatar from "~/components/Domain/User/UserAvatar.vue"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | import { VForm } from "~/types/vuetify"; | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  | import { UserOut } from "~/types/api-types/user"; | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |   components: { | 
					
						
							|  |  |  |     UserAvatar, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |   setup() { | 
					
						
							|  |  |  |     const nuxtContext = useContext(); | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  |     const user = computed(() => nuxtContext.$auth.user as unknown as UserOut); | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     watch(user, () => { | 
					
						
							|  |  |  |       userCopy.value = { ...user.value }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const userCopy = ref({ ...user.value }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const api = useUserApi(); | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const domUpdatePassword = ref<VForm | null>(null); | 
					
						
							|  |  |  |     const password = reactive({ | 
					
						
							|  |  |  |       current: "", | 
					
						
							|  |  |  |       newOne: "", | 
					
						
							|  |  |  |       newTwo: "", | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |     const passwordsMatch = computed(() => password.newOne === password.newTwo && password.newOne.length > 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |     async function updateUser() { | 
					
						
							|  |  |  |       const { response } = await api.users.updateOne(userCopy.value.id, userCopy.value); | 
					
						
							|  |  |  |       if (response?.status === 200) { | 
					
						
							|  |  |  |         nuxtContext.$auth.fetchUser(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function updatePassword() { | 
					
						
							|  |  |  |       if (!userCopy.value?.id) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       const { response } = await api.users.changePassword(userCopy.value.id, { | 
					
						
							|  |  |  |         currentPassword: password.current, | 
					
						
							|  |  |  |         newPassword: password.newOne, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (response?.status === 200) { | 
					
						
							|  |  |  |         console.log("Password Changed"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |     const state = reactive({ | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |       hideImage: false, | 
					
						
							|  |  |  |       passwordLoading: false, | 
					
						
							|  |  |  |       showPassword: false, | 
					
						
							|  |  |  |       loading: false, | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { ...toRefs(state), updateUser, updatePassword, userCopy, password, domUpdatePassword, passwordsMatch }; | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       title: this.$t("settings.profile") as string, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |