authentication

This commit is contained in:
paola.trabucco
2024-08-07 14:53:43 +02:00
parent ae95f2b4cc
commit e20f7521bb
7 changed files with 134 additions and 24 deletions

View File

@@ -1,36 +1,64 @@
<script setup>
import { useLayout } from '@/layout/composables/layout';
import { useAuth } from '@websanova/vue-auth/src/v3.js';
import Message from 'primevue/message';
import { computed, ref } from 'vue';
const auth = useAuth();
const { isDarkTheme } = useLayout();
const email = ref('');
const username = ref('');
const password = ref('');
const checked = ref(false);
const error = ref('');
const visible = ref(false);
const logoUrl = computed(() => {
return `/layout/images/${isDarkTheme ? 'logo-white' : 'logo-dark'}.svg`;
});
const login = async () => {
console.log('Username: ', username.value);
try {
await auth.login({
data:{
"username":username.value,
"password":password.value
},
redirect:'/',
fetchUser: true,
url: '/api/auth/login'
})
} catch (err) {
console.log( 'Error ' + err)
error.value = 'Incorrect username or password. Please try again.';
visible.value = true;
setTimeout(() => {
visible.value = false;
}, 3500);
}
}
</script>
<template>
<div class="bg-surface-50 dark:bg-surface-950 flex items-center justify-center min-h-screen min-w-[100vw] overflow-hidden">
<div class="flex flex-col items-center justify-center">
<img :src="logoUrl" alt="Sakai logo" class="mb-8 w-24 shrink-0" />
<div style="border-radius: 56px; padding: 0.3rem; background: linear-gradient(180deg, var(--primary-color) 10%, rgba(33, 150, 243, 0) 30%)">
<div class="w-full bg-surface-0 dark:bg-surface-900 py-20 px-8 sm:px-20" style="border-radius: 53px">
<div class="text-center mb-8">
<img src="/demo/images/login/avatar.png" alt="Image" height="50" class="mb-4" />
<div class="text-surface-900 dark:text-surface-0 text-3xl font-medium mb-4">Welcome, Isabel!</div>
<span class="text-surface-600 dark:text-surface-200 font-medium">Sign in to continue</span>
<h1>Welcome to HERMIONE</h1>
</div>
<div>
<label for="email1" class="block text-surface-900 dark:text-surface-0 text-xl font-medium mb-2">Email</label>
<InputText id="email1" type="text" placeholder="Email address" class="w-full md:w-[30rem] mb-8" style="padding: 1rem" v-model="email" />
<label for="email1" class="block text-surface-900 dark:text-surface-0 text-xl font-medium mb-2">Username</label>
<InputText id="email1" type="text" placeholder="Username" class="w-full md:w-[30rem] mb-8" style="padding: 1rem" v-model="username" />
<label for="password1" class="block text-surface-900 dark:text-surface-0 font-medium text-xl mb-2">Password</label>
<Password id="password1" v-model="password" placeholder="Password" :toggleMask="true" class="w-full mb-4" inputClass="w-full" :inputStyle="{ padding: '1rem' }"></Password>
<!--
<div class="flex items-center justify-between mb-8 gap-8">
<div class="flex items-center">
<Checkbox v-model="checked" id="rememberme1" binary class="mr-2"></Checkbox>
@@ -38,7 +66,10 @@ const logoUrl = computed(() => {
</div>
<a class="font-medium no-underline ml-2 text-right cursor-pointer" style="color: var(--primary-color)">Forgot password?</a>
</div>
<Button label="Sign In" class="w-full p-4 text-xl"></Button>
-->
<Button @click="login" label="Sign In" class="w-full p-4 text-xl"></Button>
<Message v-if="visible" severity="error" :life="3000" class="mt-2">{{ error }}</Message>
</div>
</div>
</div>