This repository has been archived on 2024-07-10. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/views/Register.vue

85 lines
2.4 KiB
Vue
Raw Normal View History

2023-08-31 20:35:39 +00:00
<template>
<v-app>
<top-bar :show-back-icon="true" :page-title="pageTitle" />
<v-main>
<v-container>
<v-form name="register-form">
<div class="mb-3">
<label for="username">Username: </label>
<input type="text" id="username" v-model="input.username" />
</div>
<div class="mb-3">
<label for="password">Password: </label>
<input type="password" id="password" v-model="input.password" />
</div>
<div class="mb-3">
<label for="password">Password Confirmation: </label>
2023-08-31 20:55:00 +00:00
<input type="password" id="passwordConfirm" v-model="input.passwordConfirm" />
2023-08-31 20:35:39 +00:00
</div>
</v-form>
</v-container>
2023-09-24 11:35:25 +00:00
<v-btn @click.prevent="register">สมครสมาช</v-btn>
2023-08-31 20:35:39 +00:00
</v-main>
</v-app>
</template>
<script>
import TopBar from '@/components/TopBar.vue';
export default {
components: {
TopBar
},
name: 'register',
data() {
return {
2023-08-31 20:55:00 +00:00
pageTitle: 'สมัครสมาชิค',
2023-08-31 20:35:39 +00:00
input: {
username: '',
password: '',
passwordConfirm:''
}
};
},
methods: {
2023-09-24 11:35:25 +00:00
register() {
if (this.input.username !== '' && ((this.input.password !='') && (this.input.password == this.input.passwordConfirm))) {
2023-08-31 20:35:39 +00:00
console.log('Authenticated: Checking with Backend');
2023-09-24 11:35:25 +00:00
fetch("http://localhost:5000/api/users/create", {
method: "POST",
body: JSON.stringify({
username: username,
password: password,
email: "",
isGoogleAccount: false
})
})
.then((res) => {
if(res.ok){
return res.json()
}
else{
return res.json().then(data => {throw Error(`${data.registerStatus}`) });
}
})
.then((data) => {
console.log(data.registerStatus)
this.$router.push({name : 'login'})
})
.catch((err) =>{
console.log(err)
})
console.log("fisnished fetch");
2023-08-31 20:35:39 +00:00
} else {
console.log('Username and Password cannot be empty');
}
}
}
};
</script>