New login page

This commit is contained in:
jableader 2024-05-21 21:08:55 +10:00
parent 626500efb1
commit 02a8ad336b
2 changed files with 53 additions and 17 deletions

View file

@ -1,19 +1,51 @@
<template>
<div class="login">
<h1>Login</h1>
<form>
<div class="form-group">
<label for="username">Username</label>
<input v-model="username" type="text" class="form-control" id="username" placeholder="Username">
</div>
<button type="button" class="btn btn-primary" @click="login">Login</button>
</form>
<h1>Login Page</h1>
<ul class="button-group">
<li v-for="person in persons" :key="person.id">
<button type="button" class="btn btn-primary" @click="login(person)">
{{ person.name }}
</button>
</li>
</ul>
</div>
</template>
<style scoped>
/* Remove the default list styling */
ul {
list-style-type: none;
padding: 0;
}
/* Center the buttons in the middle of the page, and let them wrap */
.button-group {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
/* Display each button as a large round circle */
button {
width: 100px;
height: 100px;
border-radius: 50%;
margin: 10px;
font-size: 1.5em;
/* Center the text in the middle of the button */
display: flex;
justify-content: center;
align-items: center;
}
</style>
<script>
import data from '@/data';
@ -23,16 +55,19 @@ export default {
redirect: {
type: String,
default: '/'
}
},
},
data() {
return {
username: '',
persons: [],
}
},
async beforeMount() {
this.persons = await data.getPersonsInHome();
},
methods: {
async login() {
const person = await data.login(this.username);
async login(selectedPerson) {
const person = await data.login(selectedPerson.name);
if (person?.id >= 0) {
this.$router.push(this.redirect);
return;
@ -43,7 +78,4 @@ export default {
}
}
</script>
<style>
</style>
</script>

View file

@ -294,5 +294,9 @@ export default {
fixDates(lst, "ShoppingList");
return lst;
},
async getPersonsInHome() {
const response = await fetch(BASE_URL + "/persons");
return await response.json();
}
}