| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <template>
- <q-page class="login-page column items-center justify-center">
- <div class="login-overlay" />
- <div class="login-card column items-center">
- <div class="column items-center fields-card">
- <q-img :src="Logo" class="login-logo q-mb-lg" />
- <UserTypeBadge :tipo="tipo" />
- <p class="login-title">{{ $t("auth.enter_code_title") }}</p>
- <div class="code-input-container q-mb-md" @click="focusCodeInput">
- <div class="code-slots row items-end justify-center">
- <div
- v-for="i in 6"
- :key="i"
- class="code-slot"
- :class="{
- 'code-slot--filled': (form.codigo?.length ?? 0) >= i,
- 'code-slot--active': inputFocused && (form.codigo?.length ?? 0) === i - 1,
- }"
- >
- <span class="code-char">{{ form.codigo?.[i - 1] ?? "" }}</span>
- </div>
- </div>
- <input
- ref="codeInputRef"
- v-model="form.codigo"
- class="code-hidden-input"
- maxlength="6"
- inputmode="numeric"
- autocomplete="one-time-code"
- :disabled="loading"
- @focus="inputFocused = true"
- @blur="inputFocused = false"
- @input="onCodeInput"
- @keydown="filterNonNumeric"
- />
- </div>
- <div v-if="loading" class="q-mb-md">
- <q-spinner color="violet-normal" size="24px" />
- </div>
- <p class="email-text q-py-md">{{ email }}</p>
- <q-btn
- unelevated
- :label="$t('common.actions.resend_email')"
- color="violet-normal"
- class="resend-btn"
- :loading="resending"
- @click="onResend"
- />
- <div class="column items-center q-mt-sm q-pt-md">
- <a href="#" class="login-link q-py-md" @click.prevent="goToLogin">
- {{ $t("auth.remember_password") }}
- <strong>{{ $t("auth.do_login") }}</strong>
- </a>
- <a href="#" class="login-link q-mt-xs q-pt-md" @click.prevent="goBack">
- <q-icon name="mdi-arrow-left" size="12px" class="q-mr-xs" />
- {{ $t("auth.back_to_site") }}
- </a>
- </div>
- </div>
- </div>
- </q-page>
- </template>
- <script setup>
- import { ref, nextTick } from "vue";
- import { useRouter, useRoute } from "vue-router";
- import { useQuasar } from "quasar";
- import { useSubmitHandler } from "src/composables/useSubmitHandler";
- import { verifyCode, forgotPassword } from "src/api/auth";
- import Logo from "src/assets/logo_serprati.svg";
- import UserTypeBadge from "./components/UserTypeBadge.vue";
- const router = useRouter();
- const route = useRoute();
- const $q = useQuasar();
- const email = route.query.email ?? "";
- const tipo = route.query.tipo ?? "administrador";
- const codeInputRef = ref(null);
- const inputFocused = ref(false);
- const resending = ref(false);
- const form = ref({ codigo: "" });
- const { loading, execute: submitForm } = useSubmitHandler({
- onSuccess: () =>
- router.push({ name: "ResetPasswordPage", query: { email, tipo, codigo: form.value.codigo } }),
- onError: () => {
- $q.notify({ type: "negative", message: "Código inválido. Verifique e tente novamente." });
- form.value.codigo = "";
- nextTick(() => codeInputRef.value?.focus());
- },
- });
- const focusCodeInput = () => codeInputRef.value?.focus();
- const filterNonNumeric = (e) => {
- const allowed = ["Backspace", "Delete", "Tab", "ArrowLeft", "ArrowRight"];
- if (!allowed.includes(e.key) && !/^\d$/.test(e.key)) {
- e.preventDefault();
- }
- };
- const onCodeInput = async () => {
- form.value.codigo = (form.value.codigo ?? "").replace(/\D/g, "").slice(0, 6);
- if (form.value.codigo.length === 6) {
- await submitForm(() => verifyCode(email, form.value.codigo));
- }
- };
- const onResend = async () => {
- resending.value = true;
- try {
- await forgotPassword(email, tipo);
- $q.notify({ type: "positive", message: "Código reenviado!" });
- } catch {
- $q.notify({ type: "negative", message: "Não foi possível reenviar. Tente novamente." });
- } finally {
- resending.value = false;
- }
- };
- const goToLogin = () => router.push({ name: "LoginPage" });
- const goBack = () => router.push({ name: "LoginPage" });
- </script>
- <style lang="scss" scoped>
- @use "sass:map";
- @use "src/css/quasar.variables.scss" as *;
- .login-page {
- min-height: 100dvh;
- background-image: url("src/assets/pessoas_fundo.jpg");
- background-size: cover;
- background-position: center;
- position: relative;
- }
- .login-overlay {
- position: absolute;
- inset: 0;
- background: rgba(74, 20, 140, 0.48);
- z-index: 0;
- }
- .login-card {
- z-index: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- width: calc(100% - 32px);
- min-height: calc(100dvh - 32px);
- background: rgba(255, 255, 255, 0.747);
- border-radius: 16px;
- box-shadow: 0 4px 32px rgba(0, 0, 0, 0.15);
- }
- .fields-card {
- width: 100%;
- max-width: 600px;
- padding: 32px;
- border-radius: 12px;
- }
- .login-logo {
- width: 380px;
- max-width: 100%;
- }
- .login-title {
- color: map.get($colors, "violet-normal");
- font-size: 18px;
- font-weight: 700;
- margin: 0 0 24px;
- text-align: center;
- }
- .code-input-container {
- position: relative;
- cursor: text;
- width: 100%;
- display: flex;
- justify-content: center;
- }
- .code-hidden-input {
- position: absolute;
- opacity: 0;
- pointer-events: none;
- width: 1px;
- height: 1px;
- top: 0;
- left: 0;
- }
- .code-slots {
- display: flex;
- gap: 16px;
- }
- .code-slot {
- width: 40px;
- height: 52px;
- display: flex;
- align-items: flex-end;
- justify-content: center;
- padding-bottom: 6px;
- border-bottom: 2.5px solid map.get($colors, "violet-normal");
- position: relative;
- transition: border-color 0.15s;
- &--filled {
- border-bottom-color: map.get($colors, "violet-normal-hover");
- }
- &--active {
- border-bottom-color: map.get($colors, "violet-normal-active");
- &::after {
- content: "";
- position: absolute;
- bottom: 6px;
- width: 1.5px;
- height: 20px;
- background: map.get($colors, "violet-normal");
- animation: blink-cursor 1s step-end infinite;
- }
- }
- }
- .code-char {
- font-size: 22px;
- font-weight: 700;
- color: map.get($colors, "violet-normal");
- line-height: 1;
- }
- @keyframes blink-cursor {
- 0%, 100% { opacity: 1; }
- 50% { opacity: 0; }
- }
- .email-text {
- color: map.get($colors, "violet-normal");
- font-size: 14px;
- font-weight: 500;
- text-align: center;
- margin: 0;
- }
- .resend-btn {
- font-size: 13px;
- height: 44px;
- font-weight: 600;
- letter-spacing: 0.5px;
- }
- .login-link {
- color: map.get($colors, "violet-normal");
- font-size: 13px;
- text-decoration: none;
- cursor: pointer;
- &:hover {
- color: map.get($colors, "violet-normal-hover");
- text-decoration: underline;
- }
- }
- @media (max-width: 599px) {
- .fields-card {
- padding: 52px 16px 20px;
- }
- .login-logo {
- width: 240px;
- }
- }
- </style>
|