|
91 | 91 | </div> |
92 | 92 | </div> |
93 | 93 | </div> |
| 94 | + |
| 95 | + <div class="password-section"> |
| 96 | + <div class="password-header"> |
| 97 | + <span class="password-label">Password</span> |
| 98 | + <b-button |
| 99 | + v-if="!showChangePassword" |
| 100 | + size="is-small" |
| 101 | + @click="showChangePassword = true" |
| 102 | + > |
| 103 | + Change Password |
| 104 | + </b-button> |
| 105 | + </div> |
| 106 | + <div v-if="showChangePassword" class="password-change-form"> |
| 107 | + <b-field label="Current password"> |
| 108 | + <b-input |
| 109 | + v-model="currentPassword" |
| 110 | + type="password" |
| 111 | + placeholder="Enter current password" |
| 112 | + size="is-small" |
| 113 | + password-reveal |
| 114 | + /> |
| 115 | + </b-field> |
| 116 | + <b-field label="New password"> |
| 117 | + <b-input |
| 118 | + v-model="newPassword" |
| 119 | + type="password" |
| 120 | + placeholder="Enter new password" |
| 121 | + size="is-small" |
| 122 | + password-reveal |
| 123 | + /> |
| 124 | + </b-field> |
| 125 | + <b-field label="Confirm new password"> |
| 126 | + <b-input |
| 127 | + v-model="confirmPassword" |
| 128 | + type="password" |
| 129 | + placeholder="Confirm new password" |
| 130 | + size="is-small" |
| 131 | + password-reveal |
| 132 | + /> |
| 133 | + </b-field> |
| 134 | + <div class="password-change-actions"> |
| 135 | + <b-button |
| 136 | + size="is-small" |
| 137 | + type="is-primary" |
| 138 | + @click="changePassword" |
| 139 | + :loading="passwordSaving" |
| 140 | + > |
| 141 | + Update Password |
| 142 | + </b-button> |
| 143 | + <b-button size="is-small" @click="cancelChangePassword"> |
| 144 | + Cancel |
| 145 | + </b-button> |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + </div> |
94 | 149 | </div> |
95 | 150 |
|
96 | 151 | <div class="settings-card"> |
@@ -311,6 +366,13 @@ const emailLoading = ref(false); |
311 | 366 | const emailSaving = ref(false); |
312 | 367 | const showChangeEmail = ref(false); |
313 | 368 |
|
| 369 | +// Password change |
| 370 | +const showChangePassword = ref(false); |
| 371 | +const currentPassword = ref(''); |
| 372 | +const newPassword = ref(''); |
| 373 | +const confirmPassword = ref(''); |
| 374 | +const passwordSaving = ref(false); |
| 375 | +
|
314 | 376 | const themeOptions = [ |
315 | 377 | { value: 'light', label: 'Light', icon: 'fas fa-sun' }, |
316 | 378 | { value: 'dark', label: 'Dark', icon: 'fas fa-moon' }, |
@@ -449,6 +511,79 @@ const removeEmail = async () => { |
449 | 511 | } |
450 | 512 | }; |
451 | 513 |
|
| 514 | +const changePassword = async () => { |
| 515 | + // Validate inputs |
| 516 | + if (!currentPassword.value) { |
| 517 | + buefy?.toast.open({ |
| 518 | + message: 'Please enter your current password', |
| 519 | + type: 'is-danger', |
| 520 | + duration: 3000, |
| 521 | + }); |
| 522 | + return; |
| 523 | + } |
| 524 | +
|
| 525 | + if (!newPassword.value) { |
| 526 | + buefy?.toast.open({ |
| 527 | + message: 'Please enter a new password', |
| 528 | + type: 'is-danger', |
| 529 | + duration: 3000, |
| 530 | + }); |
| 531 | + return; |
| 532 | + } |
| 533 | +
|
| 534 | + if (newPassword.value.length < 4) { |
| 535 | + buefy?.toast.open({ |
| 536 | + message: 'Password must be at least 4 characters', |
| 537 | + type: 'is-danger', |
| 538 | + duration: 3000, |
| 539 | + }); |
| 540 | + return; |
| 541 | + } |
| 542 | +
|
| 543 | + if (newPassword.value !== confirmPassword.value) { |
| 544 | + buefy?.toast.open({ |
| 545 | + message: 'New passwords do not match', |
| 546 | + type: 'is-danger', |
| 547 | + duration: 3000, |
| 548 | + }); |
| 549 | + return; |
| 550 | + } |
| 551 | +
|
| 552 | + passwordSaving.value = true; |
| 553 | + try { |
| 554 | + await Requests.put('/settings/password', { |
| 555 | + current_password: currentPassword.value, |
| 556 | + new_password: newPassword.value, |
| 557 | + }); |
| 558 | + // Clear form and hide it |
| 559 | + currentPassword.value = ''; |
| 560 | + newPassword.value = ''; |
| 561 | + confirmPassword.value = ''; |
| 562 | + showChangePassword.value = false; |
| 563 | + buefy?.toast.open({ |
| 564 | + message: 'Password changed successfully', |
| 565 | + type: 'is-success', |
| 566 | + duration: 2000, |
| 567 | + }); |
| 568 | + } catch (e: unknown) { |
| 569 | + const error = e as { response?: { data?: { error?: string } } }; |
| 570 | + buefy?.toast.open({ |
| 571 | + message: error?.response?.data?.error || 'Unable to change password', |
| 572 | + type: 'is-danger', |
| 573 | + duration: 3000, |
| 574 | + }); |
| 575 | + } finally { |
| 576 | + passwordSaving.value = false; |
| 577 | + } |
| 578 | +}; |
| 579 | +
|
| 580 | +const cancelChangePassword = () => { |
| 581 | + currentPassword.value = ''; |
| 582 | + newPassword.value = ''; |
| 583 | + confirmPassword.value = ''; |
| 584 | + showChangePassword.value = false; |
| 585 | +}; |
| 586 | +
|
452 | 587 | const onAutoSaveChange = (value: boolean) => { |
453 | 588 | // Update the setting immediately |
454 | 589 | sidebar.toggleAutoSave(value); |
@@ -1144,4 +1279,37 @@ const close = () => { |
1144 | 1279 | display: flex; |
1145 | 1280 | gap: 8px; |
1146 | 1281 | } |
| 1282 | +
|
| 1283 | +/* Password management */ |
| 1284 | +.password-section { |
| 1285 | + margin-top: 16px; |
| 1286 | + padding-top: 16px; |
| 1287 | + border-top: 1px solid var(--border-color); |
| 1288 | +} |
| 1289 | +
|
| 1290 | +.password-header { |
| 1291 | + display: flex; |
| 1292 | + justify-content: space-between; |
| 1293 | + align-items: center; |
| 1294 | +} |
| 1295 | +
|
| 1296 | +.password-label { |
| 1297 | + color: var(--text-secondary); |
| 1298 | + font-weight: 500; |
| 1299 | +} |
| 1300 | +
|
| 1301 | +.password-change-form { |
| 1302 | + display: flex; |
| 1303 | + flex-direction: column; |
| 1304 | + gap: 12px; |
| 1305 | + margin-top: 12px; |
| 1306 | + padding-top: 12px; |
| 1307 | + border-top: 1px solid var(--border-color); |
| 1308 | +} |
| 1309 | +
|
| 1310 | +.password-change-actions { |
| 1311 | + display: flex; |
| 1312 | + gap: 8px; |
| 1313 | + margin-top: 4px; |
| 1314 | +} |
1147 | 1315 | </style> |
0 commit comments