creando login

This commit is contained in:
2023-03-01 14:17:33 +01:00
parent 45e2a28412
commit f9a43e2cc6
3 changed files with 35 additions and 27 deletions

View File

@@ -5,11 +5,12 @@
<div class="column">
<div class="row">
<h5 class="text-h5 text-white q-my-md">Mis listas</h5>
<h5>{{ usuarios }}</h5>
</div>
<div class="row">
<q-card square bordered class="q-pa-lg shadow-1">
<q-card-section>
<q-form class="q-gutter-md">
<q-form class="q-gutter-md" @click.once="recibeDatos()">
<q-input
square
filled
@@ -17,6 +18,8 @@
v-model="email"
type="email"
label="email"
error-message="No coinciden"
:error="comprobarEmailVerified"
/>
<q-input
square
@@ -35,7 +38,7 @@
size="lg"
class="full-width"
label="Login"
@click="listaStore.login(email, password)"
@click="login()"
/>
</q-card-actions>
<q-card-section class="text-center q-pa-none">
@@ -52,11 +55,37 @@
</template>
<script setup>
import { ref } from "vue";
import { ref, computed } from "vue";
import { useListaStore } from "../stores/lista.js";
import { useRouter } from "vue-router";
const listaStore = useListaStore();
const $router = useRouter();
const email = ref("");
const password = ref("");
const usuarios = ref([]);
const comprobarEmailVerified = computed(() => {
//Aquí se comprueba si el usuario existe en la BD, y si está verificado
return true;
});
const recibeDatos = () => {
listaStore.getUsers().then((item) => {
usuarios.value = item;
});
};
//Falta que no pueda loguearse si no está verificado
const login = () => {
listaStore
.login(email.value, password.value)
.then((r) => {
$router.push("/");
})
.catch((e) => {
console.log("Fallo de autenticación");
});
};
</script>
<style>

View File

@@ -121,7 +121,6 @@ const recibeDatos = () => {
listaStore.getUsers().then(function (item) {
usuarios.value = item;
});
console.log(usuarios.value);
};
const comprobarUsername = computed(() => {
let filtro = usuarios.value?.filter(

View File

@@ -7,31 +7,11 @@ export const useListaStore = defineStore("lista", () => {
const authData = ref("");
async function login(email, password) {
const resultList = await pb
.collection("users")
.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");
}
}
return await pb.collection("users").authWithPassword(email, password);
}
async function refresh() {
const authData = await pb.collection("users").authRefresh();
return await pb.collection("users").authRefresh();
}
async function logout() {
@@ -46,7 +26,7 @@ export const useListaStore = defineStore("lista", () => {
}
async function register(data) {
console.log(data);
const record = await pb
return await pb
.collection("users")
.create(data)
.then((r) => {