LoginPage.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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: 738px;
  9. width: 100%;
  10. height: 100%;
  11. border-radius: 15px;
  12. "
  13. >
  14. <div class="column flex-center full-width">
  15. <q-img
  16. :src="Logo"
  17. style="max-width: 611px; max-height: 171px; height: 100%; width: 100%"
  18. />
  19. <div class="text-h4 q-mt-xl text-primary" style="font-weight: 400">
  20. Faça seu Login
  21. </div>
  22. <div
  23. class="items-center full-width q-px-lg q-mt-xl"
  24. style="display: flex; gap: 12px"
  25. >
  26. <div class="bg-primary" style="height: 1px; flex: 1"></div>
  27. <q-icon name="mdi-chevron-down" size="lg" color="warning" />
  28. <div class="bg-primary" style="height: 1px; flex: 1"></div>
  29. </div>
  30. </div>
  31. <DefaultForm
  32. ref="formRef"
  33. class="full-width q-px-lg column q-gutter-y-md q-mt-xs"
  34. autocorrect="off"
  35. autocapitalize="off"
  36. autocomplete="off"
  37. spellcheck="false"
  38. @submit="onSubmit"
  39. >
  40. <DefaultInput
  41. v-model="form.email"
  42. :error="!!validationErrors.email"
  43. :error-message="validationErrors.email"
  44. type="email"
  45. lazy-rules
  46. style="color: red"
  47. icon="mdi-account"
  48. :label="$t('common.terms.email')"
  49. :rules="[inputRules.required, inputRules.email]"
  50. />
  51. <DefaultPasswordInput
  52. v-model="form.password"
  53. :error="!!validationErrors.password"
  54. :error-message="validationErrors.password"
  55. :rules="[inputRules.required, inputRules.min(6)]"
  56. :label="$t('common.terms.password')"
  57. />
  58. <span
  59. class="q-ma-xs text-body2 text-primary cursor-pointer"
  60. style="letter-spacing: 0.25px"
  61. @click="$router.push({ name: 'ForgotMyPasswordPage' })"
  62. >Esqueceu sua senha?</span
  63. >
  64. <div>
  65. <q-btn
  66. class="full-width q-mt-md"
  67. color="primary-2"
  68. label="Entrar"
  69. size="md"
  70. padding="sm"
  71. type="submit"
  72. :loading
  73. >
  74. <template #loading>
  75. <q-spinner />
  76. </template>
  77. </q-btn>
  78. </div>
  79. </DefaultForm>
  80. </div>
  81. </q-page>
  82. </template>
  83. <script setup>
  84. import { ref, onBeforeMount, useTemplateRef } from "vue";
  85. import { useQuasar } from "quasar";
  86. import { useAuth } from "src/composables/useAuth";
  87. import { useRouter } from "vue-router";
  88. import { useInputRules } from "src/composables/useInputRules";
  89. import { useSubmitHandler } from "src/composables/useSubmitHandler";
  90. import Logo from "src/assets/images/logo.svg";
  91. import DefaultInput from "src/components/defaults/DefaultInput.vue";
  92. import DefaultPasswordInput from "src/components/defaults/DefaultPasswordInput.vue";
  93. const router = useRouter();
  94. const $q = useQuasar();
  95. const { inputRules } = useInputRules();
  96. const { login } = useAuth();
  97. const formRef = useTemplateRef("formRef");
  98. const {
  99. loading,
  100. validationErrors,
  101. execute: submitForm,
  102. } = useSubmitHandler({
  103. onSuccess: () => router.push({ name: "DashboardPage" }),
  104. formRef: formRef,
  105. });
  106. const form = ref({
  107. email: null,
  108. password: process.env.PASSWORD ?? null,
  109. });
  110. const checkbox = ref(false);
  111. const onSubmit = async () => {
  112. await submitForm(() => login(form.value.email, form.value.password));
  113. const email_storage = $q.cookies.get("email");
  114. if (email_storage && !checkbox.value) {
  115. $q.cookies.remove("email");
  116. }
  117. if (checkbox.value) {
  118. $q.cookies.set("email", form.value.email, {
  119. path: "/",
  120. sameSite: "Lax",
  121. });
  122. }
  123. };
  124. onBeforeMount(() => {
  125. const email_storage = $q.cookies.get("email");
  126. if (email_storage) {
  127. checkbox.value = true;
  128. form.value.email = email_storage;
  129. }
  130. });
  131. </script>
  132. <style lang="scss" scoped>
  133. .login-page {
  134. background-image: url("../../assets/images/background.png");
  135. background-size: cover;
  136. background-repeat: no-repeat;
  137. background-position: center;
  138. }
  139. </style>