UserProfileEditPassword.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import { useMainStore } from "@/stores/main";
  4. import { storeToRefs } from "pinia";
  5. import router from "@/router";
  6. import { password1Rules, usePassword2Rules } from "@/utils";
  7. import type { IUserProfileUpdate } from "@/interfaces";
  8. import { useI18n } from "vue-i18n";
  9. const { t } = useI18n();
  10. const valid = ref(true);
  11. const password1 = ref("");
  12. const password2 = ref("");
  13. const form = ref(null);
  14. const mainStore = useMainStore();
  15. const mainStoreRef = storeToRefs(mainStore);
  16. const userProfile = mainStoreRef.readUserProfile;
  17. const password2Rules = usePassword2Rules(password1);
  18. function reset() {
  19. password1.value = "";
  20. password2.value = "";
  21. }
  22. function cancel() {
  23. router.back();
  24. }
  25. async function submit() {
  26. await (form as any).value.validate();
  27. if (valid.value) {
  28. const updatedProfile: IUserProfileUpdate = {};
  29. updatedProfile.password = password1.value;
  30. await mainStore.updateUserProfile(updatedProfile);
  31. router.push("/main/profile");
  32. }
  33. }
  34. </script>
  35. <template>
  36. <v-container fluid>
  37. <v-card class="ma-3 pa-3">
  38. <v-card-title primary-title class="mb-3">
  39. <h3 class="headline primary--text">{{ t("changePassword") }}</h3>
  40. </v-card-title>
  41. <v-card-text>
  42. <!-- <div class="my-3">
  43. <div class="subheading secondary--text text--lighten-2">User</div>
  44. <div
  45. class="title primary--text text--darken-2"
  46. v-if="userProfile && userProfile.full_name"
  47. >
  48. {{ userProfile.full_name }}
  49. </div>
  50. <div class="title primary--text text--darken-2" v-else>
  51. {{ userProfile!.email }}
  52. </div>
  53. </div> -->
  54. <v-form ref="form" v-model="valid">
  55. <v-text-field
  56. type="password"
  57. ref="password"
  58. :label="$t('newPassword')"
  59. v-model="password1"
  60. :rules="password1Rules"
  61. >
  62. </v-text-field>
  63. <v-text-field
  64. type="password"
  65. :label="$t('confirmNewPassword')"
  66. :rules="password2Rules"
  67. v-model="password2"
  68. >
  69. </v-text-field>
  70. </v-form>
  71. </v-card-text>
  72. <v-card-actions>
  73. <v-spacer></v-spacer>
  74. <v-btn @click="cancel">{{ t("cancel") }}</v-btn>
  75. <v-btn @click="reset">{{ t("clear") }}</v-btn>
  76. <v-btn @click="submit" :disabled="!valid">{{ t("save") }}</v-btn>
  77. </v-card-actions>
  78. </v-card>
  79. </v-container>
  80. </template>