ForgotMyPasswordPage.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <q-page class="column justify-center items-center login-page">
  3. <div
  4. flat
  5. class="column justify-center items-center flex-grow full-width z-top bg-background"
  6. style="
  7. max-width: 659px;
  8. max-height: 539px;
  9. width: 100%;
  10. height: 100%;
  11. border-radius: 15px;
  12. "
  13. >
  14. <div class="flex full-width q-gutter-x-sm items-center q-mb-xl">
  15. <q-icon
  16. name="mdi-arrow-left"
  17. size="sm"
  18. color="primary"
  19. @click="currentStep === 'resend-email' ? currentStep = 'email-data' : $router.back()"
  20. />
  21. <span class="text-h6 text-weight-regular">Esqueci minha senha</span>
  22. </div>
  23. <EmailDataStep
  24. v-if="currentStep === 'email-data'"
  25. :loading
  26. :email-error="emailError"
  27. @submit="handleSubmit"
  28. @clear-error="emailError = ''"
  29. />
  30. <ResendEmailStep
  31. v-else-if="currentStep === 'resend-email'"
  32. :email
  33. :loading
  34. @resend="handleResend"
  35. />
  36. </div>
  37. </q-page>
  38. </template>
  39. <script setup>
  40. import { ref } from "vue";
  41. import EmailDataStep from "./forgot-password/EmailDataStep.vue";
  42. import ResendEmailStep from "./forgot-password/ResendEmailStep.vue";
  43. import { forgotPassword } from "src/api/auth";
  44. const currentStep = ref("email-data");
  45. const email = ref("");
  46. const loading = ref(false);
  47. const emailError = ref("");
  48. async function handleSubmit(submittedEmail) {
  49. loading.value = true;
  50. emailError.value = "";
  51. try {
  52. await forgotPassword(submittedEmail);
  53. email.value = submittedEmail;
  54. currentStep.value = "resend-email";
  55. } catch (err) {
  56. if (err.response?.status === 422) {
  57. emailError.value = err.response.data.message;
  58. }
  59. } finally {
  60. loading.value = false;
  61. }
  62. }
  63. async function handleResend() {
  64. loading.value = true;
  65. try {
  66. await forgotPassword(email.value);
  67. } finally {
  68. loading.value = false;
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .login-page {
  74. background-image: url("/images/background.png");
  75. background-size: cover;
  76. background-repeat: no-repeat;
  77. background-position: center;
  78. }
  79. </style>