LoginPage.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <q-page padding class="login-page bg-background">
  3. <q-card flat class="login-card q-pa-md q-pt-xl bg-grey-box">
  4. <div class="text-center">
  5. <q-img src="assets/logo.png" style="max-width: 250px" />
  6. </div>
  7. <q-card-section class="text-center">
  8. <div class="text-h4">{{ $t("general.welcome") }}</div>
  9. </q-card-section>
  10. <q-form
  11. ref="loginForm"
  12. class="q-pa-md"
  13. autocorrect="off"
  14. autocapitalize="off"
  15. autocomplete="off"
  16. spellcheck="false"
  17. @submit="submitLogin"
  18. >
  19. <q-card-section class="q-mt-sm">
  20. <q-input
  21. v-model="email"
  22. filled
  23. type="email"
  24. label="Email"
  25. lazy-rules
  26. autofocus
  27. />
  28. <q-input
  29. v-model="password"
  30. :label="$t('users.password')"
  31. filled
  32. :type="isPwd ? 'password' : 'text'"
  33. class="q-mt-xs"
  34. lazy-rules
  35. >
  36. <template #append>
  37. <q-icon
  38. :name="isPwd ? 'mdi-eye-off' : 'mdi-eye'"
  39. class="cursor-pointer q-ml-md"
  40. @click="isPwd = !isPwd"
  41. />
  42. </template>
  43. </q-input>
  44. <q-checkbox v-model="checkbox" label="Lembrar email" />
  45. </q-card-section>
  46. <q-card-actions align="right">
  47. <q-btn
  48. color="primary"
  49. :label="$t('navigation.login')"
  50. size="md"
  51. padding="md"
  52. type="submit"
  53. :loading="submitting"
  54. >
  55. <template #loading>
  56. <q-spinner />
  57. </template>
  58. </q-btn>
  59. </q-card-actions>
  60. </q-form>
  61. </q-card>
  62. </q-page>
  63. </template>
  64. <script setup>
  65. import { ref, onMounted } from "vue";
  66. import { useQuasar } from "quasar";
  67. import { useAuth } from "src/composables/useAuth";
  68. import { useRouter } from "vue-router";
  69. const router = useRouter();
  70. const $q = useQuasar();
  71. const email = ref("");
  72. const password = ref(process.env.PASSWORD);
  73. const isPwd = ref(true);
  74. const submitting = ref(false);
  75. const loginForm = ref(null);
  76. const checkbox = ref(false);
  77. const submitLogin = async () => {
  78. try {
  79. submitting.value = true;
  80. const validate = await loginForm.value.validate();
  81. if (!validate) {
  82. return;
  83. }
  84. const email_storage = $q.cookies.get("email");
  85. if (email_storage && !checkbox.value) {
  86. $q.cookies.remove("email");
  87. }
  88. if (checkbox.value) {
  89. $q.cookies.set("email", email.value, {
  90. expires: "3d",
  91. path: "/",
  92. sameSite: "Lax",
  93. });
  94. }
  95. await useAuth().login(email.value, password.value);
  96. submitting.value = false;
  97. router.push({ name: "HomePage" });
  98. } catch (error) {
  99. submitting.value = false;
  100. }
  101. };
  102. onMounted(() => {
  103. const email_storage = $q.cookies.get("email");
  104. if (email_storage) {
  105. checkbox.value = true;
  106. email.value = email_storage;
  107. }
  108. if (process.env.DEV && process.env.SENHA) {
  109. password.value = process.env.SENHA;
  110. }
  111. });
  112. </script>
  113. <style lang="scss" scoped>
  114. .login-page {
  115. display: flex;
  116. justify-content: center;
  117. align-items: center;
  118. .login-card {
  119. min-width: 500px;
  120. max-width: 500px;
  121. }
  122. }
  123. </style>