login si está verificado

This commit is contained in:
2023-02-28 13:50:32 +01:00
parent a892499c3d
commit dc6c9ae938
2 changed files with 108 additions and 44 deletions

View File

@@ -1,5 +1,7 @@
<template>
<div class="bg-light-green window-height window-width row justify-center items-center">
<div
class="bg-light-green window-height window-width row justify-center items-center"
>
<div class="column">
<div class="row">
<h5 class="text-h5 text-white q-my-md">Mis listas</h5>
@@ -8,39 +10,88 @@
<q-card square bordered class="q-pa-lg shadow-1">
<q-card-section>
<q-form class="q-gutter-md" @click.once="recibeDatos()">
<q-input square filled clearable v-model="username" type="text" label="username" :rules="[
(val) =>
(val != null && val.length >= 3) || 'Mínimo 3 caracteres',
(val) => comprobarUsername || 'Ya existe en la BD',
(val) => /^[A-Z0-9]+$/i.test(val) || 'Sólo letras o números'
]" />
<q-input square filled clearable v-model="nombre" type="text" label="nombre completo" :rules="[
(val) =>
(val != null && val.length >= 3) || 'Mínimo 3 caracteres',
]" />
<q-input square filled clearable v-model="email" type="email" label="email" :rules="[
(val) =>
(val != null && val.length >= 7) || 'Mínimo 7 caracteres',
(val) =>
comprobarEmail ||
'No es un email válido o ya existe en la BD',
]" />
<q-input square filled clearable v-model="password" type="password" label="password" :rules="[
(val) =>
(val != null && val.trim().length >= 8) ||
'Mínimo 8 caracteres',
]" />
<q-input square filled clearable v-model="confirmpassword" type="password" label="repite password"
error-message="No coinciden" :error="comprobarConfirmPassword" />
<q-input
square
filled
clearable
v-model="username"
type="text"
label="username"
:rules="[
(val) =>
(val != null && val.length >= 3) || 'Mínimo 3 caracteres',
(val) => comprobarUsername || 'Ya existe en la BD',
(val) => /^[A-Z0-9]+$/i.test(val) || 'Sólo letras o números',
]"
/>
<q-input
square
filled
clearable
v-model="nombre"
type="text"
label="nombre completo"
:rules="[
(val) =>
(val != null && val.length >= 3) || 'Mínimo 3 caracteres',
]"
/>
<q-input
square
filled
clearable
v-model="email"
type="email"
label="email"
:rules="[
(val) =>
(val != null && val.length >= 7) || 'Mínimo 7 caracteres',
(val) =>
comprobarEmail ||
'No es un email válido o ya existe en la BD',
]"
/>
<q-input
square
filled
clearable
v-model="password"
type="password"
label="password"
:rules="[
(val) =>
(val != null && val.trim().length >= 8) ||
'Mínimo 8 caracteres',
]"
/>
<q-input
square
filled
clearable
v-model="confirmpassword"
type="password"
label="repite password"
error-message="No coinciden"
:error="comprobarConfirmPassword"
/>
</q-form>
</q-card-section>
<q-card-actions class="q-px-md">
<q-btn :disable="btnRegisterDisable()" unelevated color="light-green-7" size="lg" class="full-width"
label="Register" @click="registrar()" />
<q-btn
:disable="btnRegisterDisable()"
unelevated
color="light-green-7"
size="lg"
class="full-width"
label="Register"
@click="registrar()"
/>
</q-card-actions>
<q-card-section class="text-center q-pa-none">
<p class="text-grey-6">
<router-link to="/login">Are you registered? Go to Login</router-link>
<router-link to="/login"
>Are you registered? Go to Login</router-link
>
</p>
</q-card-section>
</q-card>
@@ -112,15 +163,15 @@ const btnRegisterDisable = () => {
const registrar = () => {
const data = {
'username': username.value,
'email': email.value,
'emailVisibility': true,
'password': password.value,
'passwordConfirm': confirmpassword.value,
'name': nombre.value
}
listaStore.register(data)
}
username: username.value,
email: email.value,
emailVisibility: true,
password: password.value,
passwordConfirm: confirmpassword.value,
name: nombre.value,
};
listaStore.register(data);
};
</script>
<style>

View File

@@ -7,15 +7,27 @@ export const useListaStore = defineStore("lista", () => {
const authData = ref("");
async function login(email, password) {
authData.value = pb
const resultList = await pb
.collection("users")
.authWithPassword(email, password)
.then((r) => {
this.router.push("/");
})
.catch((e) => {
console.log("error:", e);
.getFirstListItem(`email="${email}"`)
.catch(() => {
console.log("El usuario no existe");
});
if (resultList != undefined) {
if (resultList.verified) {
authData.value = pb
.collection("users")
.authWithPassword(email, password)
.then((r) => {
this.router.push("/");
})
.catch((e) => {
console.log("Email o contraseña erróneos");
});
} else {
console.log("Debe verificar el correo");
}
}
}
async function refresh() {
@@ -43,6 +55,7 @@ export const useListaStore = defineStore("lista", () => {
.requestVerification(data.email)
.then((r) => {
console.log("email enviado");
this.router.push("/login");
});
console.log("Correcto");
})