| 
									
										
										
										
											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"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <UserAvatar | 
					
						
							|  |  |  |             :tooltip="false" | 
					
						
							|  |  |  |             size="96" | 
					
						
							|  |  |  |             :user-id="userCopy.id!" | 
					
						
							|  |  |  |           /> | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |           <AppButtonUpload | 
					
						
							|  |  |  |             class="my-1" | 
					
						
							|  |  |  |             file-name="profile" | 
					
						
							|  |  |  |             accept="image/*" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             :url="`/api/users/${userCopy.id}/image`" | 
					
						
							|  |  |  |             @uploaded="$auth.refresh()" | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |           /> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |       </template> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <template #title> | 
					
						
							|  |  |  |         {{ $t("profile.user-settings") }} | 
					
						
							|  |  |  |       </template> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |     </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 }"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <v-btn | 
					
						
							|  |  |  |             v-if="!state" | 
					
						
							|  |  |  |             color="info" | 
					
						
							|  |  |  |             class="mt-2 mb-n3" | 
					
						
							|  |  |  |             @click="toggle" | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <v-icon start> | 
					
						
							|  |  |  |               {{ $globals.icons.lock }} | 
					
						
							|  |  |  |             </v-icon> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |             {{ $t("settings.change-password") }} | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <v-btn | 
					
						
							|  |  |  |             v-else | 
					
						
							|  |  |  |             color="info" | 
					
						
							|  |  |  |             class="mt-2 mb-n3" | 
					
						
							|  |  |  |             @click="toggle" | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <v-icon start> | 
					
						
							|  |  |  |               {{ $globals.icons.user }} | 
					
						
							|  |  |  |             </v-icon> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |             {{ $t("settings.profile") }} | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							|  |  |  |         </template> | 
					
						
							|  |  |  |         <template #default="{ state }"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <v-slide-x-transition | 
					
						
							|  |  |  |             leave-absolute | 
					
						
							|  |  |  |             hide-on-leave | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <div | 
					
						
							|  |  |  |               v-if="!state" | 
					
						
							|  |  |  |               key="personal-info" | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |               <BaseCardSectionTitle | 
					
						
							|  |  |  |                 class="mt-10" | 
					
						
							|  |  |  |                 :title="$t('profile.personal-information')" | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |               <v-card | 
					
						
							|  |  |  |                 tag="article" | 
					
						
							|  |  |  |                 variant="outlined" | 
					
						
							|  |  |  |                 style="border-color: lightgrey;" | 
					
						
							|  |  |  |               > | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                 <v-card-text class="pb-0"> | 
					
						
							|  |  |  |                   <v-form ref="userUpdate"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                     <v-text-field | 
					
						
							|  |  |  |                       v-model="userCopy.username" | 
					
						
							|  |  |  |                       :label="$t('user.username')" | 
					
						
							|  |  |  |                       required | 
					
						
							|  |  |  |                       validate-on="blur" | 
					
						
							|  |  |  |                       density="comfortable" | 
					
						
							|  |  |  |                       variant="underlined" | 
					
						
							|  |  |  |                     /> | 
					
						
							|  |  |  |                     <v-text-field | 
					
						
							|  |  |  |                       v-model="userCopy.fullName" | 
					
						
							|  |  |  |                       :label="$t('user.full-name')" | 
					
						
							|  |  |  |                       required | 
					
						
							|  |  |  |                       validate-on="blur" | 
					
						
							|  |  |  |                       density="comfortable" | 
					
						
							|  |  |  |                       variant="underlined" | 
					
						
							|  |  |  |                     /> | 
					
						
							|  |  |  |                     <v-text-field | 
					
						
							|  |  |  |                       v-model="userCopy.email" | 
					
						
							|  |  |  |                       :label="$t('user.email')" | 
					
						
							|  |  |  |                       validate-on="blur" | 
					
						
							|  |  |  |                       required | 
					
						
							|  |  |  |                       density="comfortable" | 
					
						
							|  |  |  |                       variant="underlined" | 
					
						
							|  |  |  |                     /> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                   </v-form> | 
					
						
							|  |  |  |                 </v-card-text> | 
					
						
							|  |  |  |                 <v-card-actions> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                   <v-spacer /> | 
					
						
							|  |  |  |                   <BaseButton | 
					
						
							|  |  |  |                     update | 
					
						
							|  |  |  |                     @click="updateUser" | 
					
						
							|  |  |  |                   /> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                 </v-card-actions> | 
					
						
							|  |  |  |               </v-card> | 
					
						
							|  |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             <div | 
					
						
							|  |  |  |               v-else | 
					
						
							|  |  |  |               key="change-password" | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |               <BaseCardSectionTitle | 
					
						
							|  |  |  |                 class="mt-10" | 
					
						
							|  |  |  |                 :title="$t('settings.change-password')" | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |               <v-card variant="outlined"> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                 <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')" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       validate-on="blur" | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                       :type="showPassword ? 'text' : 'password'" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       :append-icon="showPassword ? $globals.icons.eye : $globals.icons.eyeOff" | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |                       :rules="[validators.minLength(1)]" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       density="comfortable" | 
					
						
							|  |  |  |                       variant="underlined" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       @click:append="showPassword = !showPassword" | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |                     /> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                     <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" | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |                       :rules="[validators.minLength(8)]" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       density="comfortable" | 
					
						
							|  |  |  |                       variant="underlined" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       @click:append="showPassword = !showPassword" | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |                     /> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                     <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')]" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       validate-on="blur" | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                       :type="showPassword ? 'text' : 'password'" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       :append-icon="showPassword ? $globals.icons.eye : $globals.icons.eyeOff" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                       density="comfortable" | 
					
						
							|  |  |  |                       variant="underlined" | 
					
						
							| 
									
										
										
										
											2022-03-20 16:12:49 -08:00
										 |  |  |                       @click:append="showPassword = !showPassword" | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |                     /> | 
					
						
							| 
									
										
										
										
											2025-06-20 18:39:08 +02:00
										 |  |  |                     <UserPasswordStrength v-model="password.newOne" /> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |                   </v-form> | 
					
						
							|  |  |  |                 </v-card-text> | 
					
						
							|  |  |  |                 <v-card-actions> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |                   <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> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       <BaseCardSectionTitle | 
					
						
							|  |  |  |         class="mt-10" | 
					
						
							|  |  |  |         :title="$t('profile.preferences')" | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |       <v-checkbox | 
					
						
							|  |  |  |         v-model="userCopy.advanced" | 
					
						
							|  |  |  |         class="mt-n4" | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         :label="$t('profile.show-advanced-description')" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         color="primary" | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  |         @change="updateUser" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       /> | 
					
						
							|  |  |  |       <nuxt-link | 
					
						
							|  |  |  |         class="mt-5 d-flex flex-column justify-center text-center" | 
					
						
							|  |  |  |         :to="`/group`" | 
					
						
							|  |  |  |       > {{ | 
					
						
							|  |  |  |         $t('profile.looking-for-privacy-settings') }} </nuxt-link> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       <div class="d-flex flex-wrap justify-center mt-5"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <v-btn | 
					
						
							|  |  |  |           variant="outlined" | 
					
						
							|  |  |  |           class="rounded-xl my-1 mx-1" | 
					
						
							|  |  |  |           :to="`/user/profile`" | 
					
						
							|  |  |  |           nuxt | 
					
						
							|  |  |  |           exact | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <v-icon start> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |             {{ $globals.icons.backArrow }} | 
					
						
							|  |  |  |           </v-icon> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |           {{ $t('profile.back-to-profile') }} | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |         </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"> | 
					
						
							| 
									
										
										
										
											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-08-13 21:38:26 -08:00
										 |  |  | import UserPasswordStrength from "~/components/Domain/User/UserPasswordStrength.vue"; | 
					
						
							|  |  |  | import { validators } from "~/composables/use-validators"; | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | import type { VForm } from "~/types/auto-forms"; | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |   components: { | 
					
						
							|  |  |  |     UserAvatar, | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |     UserPasswordStrength, | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |   middleware: "sidebase-auth", | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const i18n = useI18n(); | 
					
						
							|  |  |  |     const $auth = useMealieAuth(); | 
					
						
							|  |  |  |     const user = computed(() => $auth.user.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     useSeoMeta({ | 
					
						
							|  |  |  |       title: i18n.t("settings.profile"), | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											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() { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       if (!userCopy.value?.id) return; | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |       const { response } = await api.users.updateOne(userCopy.value.id, userCopy.value); | 
					
						
							|  |  |  |       if (response?.status === 200) { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         $auth.refresh(); | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function updatePassword() { | 
					
						
							|  |  |  |       if (!userCopy.value?.id) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-08-07 02:54:29 +02:00
										 |  |  |       const { response } = await api.users.changePassword({ | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  |         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
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 21:38:26 -08:00
										 |  |  |     return { | 
					
						
							|  |  |  |       ...toRefs(state), | 
					
						
							|  |  |  |       updateUser, | 
					
						
							|  |  |  |       updatePassword, | 
					
						
							|  |  |  |       userCopy, | 
					
						
							|  |  |  |       password, | 
					
						
							|  |  |  |       domUpdatePassword, | 
					
						
							|  |  |  |       passwordsMatch, | 
					
						
							|  |  |  |       validators, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       $auth, | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |