frontend/src/views/Login.vue

152 lines
4 KiB
Vue
Raw Normal View History

<template>
<v-app>
<top-bar :show-back-icon="true" :page-title="pageTitle" />
<v-main>
2023-10-01 02:03:16 +07:00
<div class="text-center mt-8 mb-16">
<div class="text-h4 font-weight-bold">
นดอนรบกลบส
<div>Little Lines</div>
</div>
</div>
<div class="mx-5">
<v-text-field
class="email"
v-model="input.email"
2023-10-01 02:03:16 +07:00
label="อีเมล"
variant="solo"
>
<template v-slot:append-inner>
<img
class="iconEdit"
:src="edit"
>
</template>
</v-text-field>
<v-text-field
class="password"
v-model="input.password"
label="รหัสผ่าน"
variant="solo"
>
<template v-slot:append-inner>
<img
class="iconEdit"
:src="edit"
>
<img
class="iconEyeNotLooking"
:src="eyeNotLooking"
>
</template>
</v-text-field>
</div>
2023-10-01 02:03:16 +07:00
<v-contaioner>
<v-row class="button">
<v-btn @click.prevent="login" rounded="xl" variant="flat" class="text-white" width="45vw" height="44px" color="#f16322">
ลงชอเขาใช</v-btn>
</v-row>
<v-row class="button">
<v-btn class="text-none" rounded="xl" variant="tonal" width="45vw" height="44px">
ลงชอเขาใชวย Google</v-btn>
</v-row>
<v-row class="button">
<v-btn :to="{name: 'register'}" rounded="xl" variant="tonal" width="45vw" height="44px">
นตองการสมครสมาช</v-btn>
</v-row>
</v-contaioner>
</v-main>
</v-app>
</template>
2023-10-01 02:03:16 +07:00
<script setup>
import edit from '../../icons/Material/edit.svg';
import eyeNotLooking from '../../icons/Material/eye-not-looking.svg';
</script>
<script>
2023-09-01 03:35:39 +07:00
import {RouterLink} from 'vue-router';
import TopBar from '@/components/TopBar.vue';
2023-10-01 02:03:16 +07:00
import { VContainer } from 'vuetify/lib/components/index.mjs';
export default {
components: {
TopBar
},
name: 'Login',
data() {
return {
2023-09-01 03:35:39 +07:00
pageTitle: 'ลงชื่อเข้าใช้',
input: {
email: '',
password: ''
}
};
},
methods: {
login() {
if (this.input.email !== '' && this.input.password !== '') {
console.log('Authenticated: Checking with Backend');
2023-10-12 17:28:22 +07:00
fetch(`https://little-lines-backend.techtransthai.org/api/users/login`, {
2023-09-27 00:47:59 +07:00
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: this.input.email,
2023-09-27 00:47:59 +07:00
password: this.input.password,
}),
})
.then((res) => {
if (res.ok) {
return res.json();
} else {
throw Error(`Login failed (${res.status})`);
}
})
.then((data) => {
2023-09-27 00:58:43 +07:00
console.log(data.success);
sessionStorage.setItem('current_user', data.user.username);
2023-09-27 00:47:59 +07:00
this.$router.push({ name: 'home' });
})
.catch((err) => {
console.log(err);
// Handle the error, e.g., display an error message to the user
});
} else {
console.log('Email and Password cannot be empty');
}
}
}
};
</script>
2023-10-01 02:03:16 +07:00
<style>
.username {
margin-bottom: -21px;
}
.iconEdit, .iconEyeNotLooking {
width: 25px;
height: 25px;
}
.iconEdit {
margin-right: 10px;
}
.iconEyeNotLooking {
margin-right: 10px;
margin-left: 10px;
}
.button {
padding: 10px;
display: flex;
justify-content: center;
align-content: center;
}
</style>