LoginPage.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. <q-form
  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. v-model:error="validationErrors.email"
  43. type="email"
  44. lazy-rules
  45. icon="mdi-account"
  46. :label="$t('common.terms.email')"
  47. :rules="[inputRules.required, inputRules.email]"
  48. />
  49. <DefaultPasswordInput
  50. v-model="form.password"
  51. v-model:error="validationErrors.password"
  52. :rules="[inputRules.required, inputRules.min(6)]"
  53. :label="$t('common.terms.password')"
  54. />
  55. <span
  56. class="q-ma-xs text-body2 text-primary cursor-pointer"
  57. style="letter-spacing: 0.25px"
  58. @click="$router.push({ name: 'ForgotMyPasswordPage' })"
  59. >Esqueceu sua senha?</span
  60. >
  61. <div>
  62. <q-btn
  63. class="full-width q-mt-md"
  64. color="primary-2"
  65. label="Entrar"
  66. size="md"
  67. padding="sm"
  68. type="submit"
  69. :loading
  70. >
  71. <template #loading>
  72. <q-spinner />
  73. </template>
  74. </q-btn>
  75. </div>
  76. </q-form>
  77. </div>
  78. </q-page>
  79. </template>
  80. <script setup>
  81. import { ref, onBeforeMount, useTemplateRef } from "vue";
  82. import { useQuasar } from "quasar";
  83. import { useAuth } from "src/composables/useAuth";
  84. import { useRouter } from "vue-router";
  85. import { useInputRules } from "src/composables/useInputRules";
  86. import { useSubmitHandler } from "src/composables/useSubmitHandler";
  87. import Logo from "src/assets/images/logo.svg";
  88. import DefaultInput from "src/components/defaults/DefaultInput.vue";
  89. import DefaultPasswordInput from "src/components/defaults/DefaultPasswordInput.vue";
  90. const router = useRouter();
  91. const $q = useQuasar();
  92. const { inputRules } = useInputRules();
  93. const { login } = useAuth();
  94. const formRef = useTemplateRef("formRef");
  95. const {
  96. loading,
  97. validationErrors,
  98. execute: submitForm,
  99. } = useSubmitHandler({
  100. onSuccess: () => router.push({ name: "DashboardPage" }),
  101. formRef: formRef,
  102. });
  103. const form = ref({
  104. email: null,
  105. password: process.env.PASSWORD ?? null,
  106. });
  107. const checkbox = ref(false);
  108. const onSubmit = async () => {
  109. await submitForm(() => login(form.value.email, form.value.password));
  110. const email_storage = $q.cookies.get("email");
  111. if (email_storage && !checkbox.value) {
  112. $q.cookies.remove("email");
  113. }
  114. if (checkbox.value) {
  115. $q.cookies.set("email", form.value.email, {
  116. path: "/",
  117. sameSite: "Lax",
  118. });
  119. }
  120. };
  121. onBeforeMount(() => {
  122. const email_storage = $q.cookies.get("email");
  123. if (email_storage) {
  124. checkbox.value = true;
  125. form.value.email = email_storage;
  126. }
  127. });
  128. </script>
  129. <style lang="scss" scoped>
  130. .login-page {
  131. background-image: url("../../assets/images/background.png");
  132. background-size: cover;
  133. background-repeat: no-repeat;
  134. background-position: center;
  135. }
  136. </style>