2024-04-28 02:13:49 +00:00
|
|
|
<template>
|
2025-10-18 02:08:22 +00:00
|
|
|
<div class="login">
|
|
|
|
|
<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>
|
2024-04-28 02:13:49 +00:00
|
|
|
</template>
|
|
|
|
|
|
2024-05-21 11:08:55 +00:00
|
|
|
<style scoped>
|
|
|
|
|
/* Remove the default list styling */
|
|
|
|
|
ul {
|
2025-10-18 02:08:22 +00:00
|
|
|
list-style-type: none;
|
|
|
|
|
padding: 0;
|
2024-05-21 11:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Center the buttons in the middle of the page, and let them wrap */
|
|
|
|
|
|
|
|
|
|
.button-group {
|
2025-10-18 02:08:22 +00:00
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
justify-content: center;
|
2024-05-21 11:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Display each button as a large round circle */
|
|
|
|
|
|
|
|
|
|
button {
|
2025-10-18 02:08:22 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/* Add a shadow to make the buttons look like they are floating */
|
|
|
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
2024-05-21 11:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Some nice flat nuetral shades for the user buttons */
|
|
|
|
|
|
|
|
|
|
li:nth-child(1) > button {
|
2025-10-18 02:08:22 +00:00
|
|
|
background-color: #3939ff;
|
|
|
|
|
color: white;
|
2024-05-21 11:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li:nth-child(2) > button {
|
2025-10-18 02:08:22 +00:00
|
|
|
background-color: #156a14;
|
|
|
|
|
color: white;
|
2024-05-21 11:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
2024-05-21 11:19:22 +00:00
|
|
|
li:nth-child(3) > button {
|
2025-10-18 02:08:22 +00:00
|
|
|
background-color: #325293;
|
|
|
|
|
color: white;
|
2024-05-21 11:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li:nth-child(4) > button {
|
2025-10-18 02:08:22 +00:00
|
|
|
background-color: #9a1f1f;
|
|
|
|
|
color: white;
|
2024-05-21 11:19:22 +00:00
|
|
|
}
|
2024-05-21 11:08:55 +00:00
|
|
|
</style>
|
|
|
|
|
|
2024-04-28 02:13:49 +00:00
|
|
|
<script>
|
2025-10-18 02:08:22 +00:00
|
|
|
import { getPersonsInHome } from '@/api/persons'
|
|
|
|
|
import { login } from '@/api/auth'
|
2024-04-28 02:13:49 +00:00
|
|
|
|
|
|
|
|
export default {
|
2025-10-18 02:08:22 +00:00
|
|
|
name: 'LoginVue',
|
|
|
|
|
props: {
|
|
|
|
|
redirect: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '/',
|
2024-05-21 11:08:55 +00:00
|
|
|
},
|
2025-10-18 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
persons: [],
|
2024-04-28 02:13:49 +00:00
|
|
|
}
|
2025-10-18 02:08:22 +00:00
|
|
|
},
|
|
|
|
|
async beforeMount() {
|
|
|
|
|
this.persons = await getPersonsInHome()
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async login(selectedPerson) {
|
|
|
|
|
const person = await login(selectedPerson.name)
|
|
|
|
|
if (person?.id >= 0) {
|
|
|
|
|
this.$router.push(this.redirect)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alert('Login failed')
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-04-28 02:13:49 +00:00
|
|
|
}
|
2025-10-18 02:08:22 +00:00
|
|
|
</script>
|