|
416 | 416 | }}</span> |
417 | 417 | </label> |
418 | 418 | <div> |
419 | | - <Button @click="$refs.changeEmailModal.show()"> |
| 419 | + <Button @click="openChangeEmail"> |
420 | 420 | <template v-if="auth.user.email"> |
421 | 421 | <EditIcon /> |
422 | 422 | {{ formatMessage(messages.changeEmailButton) }} |
|
443 | 443 | </span> |
444 | 444 | </label> |
445 | 445 | <div> |
446 | | - <Button |
447 | | - @click=" |
448 | | - () => { |
449 | | - oldPassword = '' |
450 | | - newPassword = '' |
451 | | - confirmNewPassword = '' |
452 | | - removePasswordMode = false |
453 | | - $refs.managePasswordModal.show() |
454 | | - } |
455 | | - " |
456 | | - > |
| 446 | + <Button @click="openPasswordModal"> |
457 | 447 | <KeyIcon /> |
458 | 448 | <template v-if="auth.user.has_password">{{ |
459 | 449 | formatMessage(messages.changePasswordButton) |
|
488 | 478 | }}</span> |
489 | 479 | </label> |
490 | 480 | <div> |
491 | | - <Button @click="$refs.manageProvidersModal.show()"> |
| 481 | + <Button @click="openManageProviders"> |
492 | 482 | <SettingsIcon /> {{ formatMessage(messages.manageProvidersButton) }} |
493 | 483 | </Button> |
494 | 484 | </div> |
|
516 | 506 | <section id="delete-account" class="universal-card"> |
517 | 507 | <h2>{{ formatMessage(messages.deleteAccountSectionTitle) }}</h2> |
518 | 508 | <p>{{ formatMessage(messages.deleteAccountSectionDescription) }}</p> |
519 | | - <Button type="colored" color="red" native-type="button" @click="$refs.modal_confirm.show()"> |
| 509 | + <Button type="colored" color="red" native-type="button" @click="openDeleteAccount"> |
520 | 510 | <TrashIcon /> |
521 | 511 | {{ formatMessage(messages.deleteAccountButton) }} |
522 | 512 | </Button> |
@@ -569,7 +559,12 @@ import TwoFactorAuthCodeInput from '~/components/ui/auth/TwoFactorAuthCodeInput. |
569 | 559 | import { forgetStoredAccount, isSessionYoung } from '~/composables/accounts.ts' |
570 | 560 | import { getAuthUrl, removeAuthProvider } from '~/composables/auth.ts' |
571 | 561 | import { useAuthCookie } from '~/composables/auth-cookie.ts' |
572 | | -import { isReauthCancelled, requestReauth, runPrivileged } from '~/composables/reauth.ts' |
| 562 | +import { |
| 563 | + ensurePrivileged, |
| 564 | + isReauthCancelled, |
| 565 | + requestReauth, |
| 566 | + runPrivileged, |
| 567 | +} from '~/composables/reauth.ts' |
573 | 568 |
|
574 | 569 | definePageMeta({ |
575 | 570 | middleware: 'auth', |
@@ -881,7 +876,25 @@ const messages = defineMessages({ |
881 | 876 | }) |
882 | 877 |
|
883 | 878 | const changeEmailModal = ref() |
| 879 | +const manageProvidersModal = ref() |
| 880 | +const modal_confirm = ref() |
884 | 881 | const email = ref(auth.value.user.email) |
| 882 | +
|
| 883 | +async function openChangeEmail() { |
| 884 | + if (!(await ensurePrivileged(Boolean(auth.value.user.email)))) return |
| 885 | + changeEmailModal.value.show() |
| 886 | +} |
| 887 | +
|
| 888 | +async function openManageProviders() { |
| 889 | + if (!(await ensurePrivileged())) return |
| 890 | + manageProvidersModal.value.show() |
| 891 | +} |
| 892 | +
|
| 893 | +async function openDeleteAccount() { |
| 894 | + if (!(await ensurePrivileged())) return |
| 895 | + modal_confirm.value.show() |
| 896 | +} |
| 897 | +
|
885 | 898 | async function saveEmail() { |
886 | 899 | if (!email.value) { |
887 | 900 | return |
@@ -942,6 +955,16 @@ const removePasswordMode = ref(false) |
942 | 955 | const oldPassword = ref('') |
943 | 956 | const newPassword = ref('') |
944 | 957 | const confirmNewPassword = ref('') |
| 958 | +
|
| 959 | +async function openPasswordModal() { |
| 960 | + if (!(await ensurePrivileged())) return |
| 961 | + oldPassword.value = '' |
| 962 | + newPassword.value = '' |
| 963 | + confirmNewPassword.value = '' |
| 964 | + removePasswordMode.value = false |
| 965 | + managePasswordModal.value.show() |
| 966 | +} |
| 967 | +
|
945 | 968 | async function savePassword() { |
946 | 969 | if (newPassword.value !== confirmNewPassword.value) { |
947 | 970 | return |
@@ -980,6 +1003,7 @@ const twoFactorCodeInput = ref() |
980 | 1003 | const removeTwoFactorCodeInput = ref() |
981 | 1004 | const twoFactorSubmitting = ref(false) |
982 | 1005 | async function showTwoFactorModal() { |
| 1006 | + if (!(await ensurePrivileged())) return |
983 | 1007 | twoFactorStep.value = 0 |
984 | 1008 | twoFactorCode.value = '' |
985 | 1009 | twoFactorIncorrect.value = false |
|
0 commit comments