2022-05-11 14:48:04 +02:00
|
|
|
<template>
|
|
|
|
<div class="container box">
|
|
|
|
<form @submit.prevent="handleSubmit">
|
|
|
|
<div
|
2022-05-23 16:25:55 +02:00
|
|
|
v-if="errorMessage"
|
|
|
|
class="alert alert-danger mt-2"
|
2022-05-11 14:48:04 +02:00
|
|
|
>
|
2022-05-23 16:25:55 +02:00
|
|
|
{{ errorMessage }}
|
2022-05-11 14:48:04 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-group mt-2">
|
|
|
|
<label for="exampleInputEmail1">Username</label>
|
|
|
|
<input
|
|
|
|
id="username"
|
|
|
|
v-model="username"
|
|
|
|
type="text"
|
|
|
|
class="form-control"
|
|
|
|
aria-describedby="emailHelp"
|
|
|
|
placeholder="Enter email"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
<div class="form-group mt-2">
|
|
|
|
<label for="password">Password</label>
|
|
|
|
<input
|
|
|
|
id="password"
|
|
|
|
v-model="password"
|
|
|
|
type="password"
|
|
|
|
class="form-control"
|
|
|
|
placeholder="Password"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
<div class="form-check mt-2">
|
|
|
|
<input
|
|
|
|
id="remember-me"
|
|
|
|
type="checkbox"
|
|
|
|
class="form-check-input"
|
|
|
|
>
|
|
|
|
<label
|
|
|
|
class="form-check-label"
|
|
|
|
for="remember-me"
|
|
|
|
>
|
|
|
|
Remember Me
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="btn btn-primary mt-2 mb-2"
|
|
|
|
:class="{ disabled: isLoading }"
|
|
|
|
>
|
|
|
|
Log in
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-05-23 16:25:55 +02:00
|
|
|
<script setup>
|
2022-05-25 14:41:58 +02:00
|
|
|
import { ref } from 'vue'
|
2022-05-11 14:48:04 +02:00
|
|
|
import axios from 'axios'
|
|
|
|
|
2022-05-23 16:25:55 +02:00
|
|
|
const username = ref('')
|
|
|
|
const password = ref('')
|
|
|
|
const errorMessage = ref('')
|
|
|
|
const isLoading = ref(false)
|
|
|
|
const emit = defineEmits(['user-authenticated'])
|
2022-05-11 14:48:04 +02:00
|
|
|
|
2022-05-23 16:25:55 +02:00
|
|
|
const handleSubmit = () => {
|
|
|
|
//console.log('handle submit')
|
|
|
|
isLoading.value = true
|
2022-05-11 14:48:04 +02:00
|
|
|
|
2022-05-23 16:25:55 +02:00
|
|
|
axios
|
|
|
|
.post('/login', {
|
|
|
|
username: username.value,
|
|
|
|
password: password.value
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
//console.log(response.headers)
|
|
|
|
|
|
|
|
emit('user-authenticated', response.headers.location)
|
|
|
|
username.value = ''
|
|
|
|
password.value = ''
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error)
|
|
|
|
console.log(error.response.data)
|
|
|
|
if (error.response.data.error) {
|
|
|
|
errorMessage.value = error.response.data.error
|
|
|
|
} else {
|
|
|
|
errorMessage.value = 'Unknown error'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
isLoading.value = false
|
|
|
|
})
|
2022-05-11 14:48:04 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
</style>
|