Changeset ae83647 for petify-frontend/src/views/ProfileView.vue
- Timestamp:
- 06/26/26 16:32:12 (45 hours ago)
- Branches:
- master
- Parents:
- fa32d0f
- File:
-
- 1 edited
-
petify-frontend/src/views/ProfileView.vue (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
petify-frontend/src/views/ProfileView.vue
rfa32d0f rae83647 94 94 </button> 95 95 </li> 96 <li class="nav-item" role="presentation"> 97 <button 98 class="nav-link" 99 :class="{ active: activeTab === 'account' }" 100 @click="activeTab = 'account'" 101 type="button" 102 role="tab" 103 > 104 <i class="bi bi-shield-lock-fill"></i> Account 105 </button> 106 </li> 96 107 </ul> 108 109 <!-- Account Tab --> 110 <div v-if="activeTab === 'account'" class="tab-content-section"> 111 <h2 class="section-title">Account</h2> 112 <form class="password-form" @submit.prevent="submitPasswordChange"> 113 <div v-if="passwordSuccess" class="alert alert-success" role="alert"> 114 {{ passwordSuccess }} 115 </div> 116 <div v-if="passwordError" class="alert alert-danger" role="alert"> 117 {{ passwordError }} 118 </div> 119 120 <div class="mb-3"> 121 <label class="form-label" for="current-password">Current password</label> 122 <input 123 id="current-password" 124 v-model="passwordForm.currentPassword" 125 class="form-control" 126 type="password" 127 autocomplete="current-password" 128 required 129 /> 130 </div> 131 132 <div class="mb-3"> 133 <label class="form-label" for="new-password">New password</label> 134 <input 135 id="new-password" 136 v-model="passwordForm.newPassword" 137 class="form-control" 138 type="password" 139 autocomplete="new-password" 140 minlength="8" 141 required 142 /> 143 </div> 144 145 <div class="mb-4"> 146 <label class="form-label" for="confirm-new-password">Confirm new password</label> 147 <input 148 id="confirm-new-password" 149 v-model="passwordForm.confirmPassword" 150 class="form-control" 151 type="password" 152 autocomplete="new-password" 153 minlength="8" 154 required 155 /> 156 </div> 157 158 <button class="btn btn-primary" type="submit" :disabled="isPasswordSubmitting"> 159 <span v-if="isPasswordSubmitting" class="spinner-border spinner-border-sm me-2" aria-hidden="true"></span> 160 {{ isPasswordSubmitting ? 'Changing...' : 'Change password' }} 161 </button> 162 </form> 163 </div> 97 164 98 165 <!-- Listings Tab --> … … 746 813 type Review, 747 814 } from '../api/reviews' 815 import { changePassword } from '../api/auth' 748 816 749 817 const router = useRouter() 750 818 const auth = useAuthStore() 751 819 752 const activeTab = ref<'listings' | 'pets' | 'create-listing' | 'favorites' | 'appointments' >('listings')820 const activeTab = ref<'listings' | 'pets' | 'create-listing' | 'favorites' | 'appointments' | 'account'>('listings') 753 821 const listings = ref<any[]>([]) 754 822 const pets = ref<any[]>([]) … … 782 850 const petPhotoFile = ref<File | null>(null) 783 851 const petPhotoPreview = ref('') 852 const isPasswordSubmitting = ref(false) 853 const passwordError = ref('') 854 const passwordSuccess = ref('') 855 856 const passwordForm = ref({ 857 currentPassword: '', 858 newPassword: '', 859 confirmPassword: '', 860 }) 784 861 785 862 const newListing = ref({ … … 859 936 // Fall back to petNameMap (from pets list) 860 937 return petNameMap.value[animalId] || 'Unknown Pet' 938 } 939 940 async function submitPasswordChange() { 941 passwordError.value = '' 942 passwordSuccess.value = '' 943 944 if (!auth.user?.userId) { 945 passwordError.value = 'You need to be logged in to change your password.' 946 return 947 } 948 if (passwordForm.value.newPassword.length < 8) { 949 passwordError.value = 'New password must be at least 8 characters long.' 950 return 951 } 952 if (passwordForm.value.newPassword !== passwordForm.value.confirmPassword) { 953 passwordError.value = 'New passwords do not match.' 954 return 955 } 956 957 isPasswordSubmitting.value = true 958 try { 959 await changePassword({ 960 userId: auth.user.userId, 961 currentPassword: passwordForm.value.currentPassword, 962 newPassword: passwordForm.value.newPassword, 963 }) 964 passwordForm.value = { 965 currentPassword: '', 966 newPassword: '', 967 confirmPassword: '', 968 } 969 passwordSuccess.value = 'Password changed successfully.' 970 } catch (error: any) { 971 passwordError.value = error?.message || 'Failed to change password.' 972 } finally { 973 isPasswordSubmitting.value = false 974 } 861 975 } 862 976 … … 1670 1784 } 1671 1785 1786 .password-form { 1787 max-width: 520px; 1788 } 1789 1672 1790 @keyframes fadeIn { 1673 1791 from {
Note:
See TracChangeset
for help on using the changeset viewer.
