mirror of
https://gitlab.com/little-lines/frontend.git
synced 2024-11-24 21:06:52 +00:00
Merge branch 'main' of https://gitlab.com/openKMITL/micromobility-navigation
This commit is contained in:
commit
c59eaff193
2 changed files with 58 additions and 5 deletions
|
@ -45,8 +45,34 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
login() {
|
||||
if (this.input.username !== '' || this.input.password !== '') {
|
||||
if (this.input.username !== '' && this.input.password !== '') {
|
||||
console.log('Authenticated: Checking with Backend');
|
||||
fetch(`http://localhost:5000/api/users/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: this.input.username,
|
||||
password: this.input.password,
|
||||
}),
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
} else {
|
||||
throw Error(`Login failed (${res.status})`);
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
console.log(data.success);
|
||||
sessionStorage.setItem('current_user', data.user.username);
|
||||
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('Username and Password cannot be empty');
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
</v-form>
|
||||
</v-container>
|
||||
|
||||
<v-btn @click.prevent="login">สมัครสมาชิค</v-btn>
|
||||
<v-btn @click.prevent="register">สมัครสมาชิค</v-btn>
|
||||
|
||||
</v-main>
|
||||
</v-app>
|
||||
|
@ -47,15 +47,42 @@
|
|||
};
|
||||
},
|
||||
methods: {
|
||||
login() {
|
||||
if (this.input.username !== '' || this.input.password !== '') {
|
||||
register() {
|
||||
if (this.input.username !== '' && ((this.input.password !='') && (this.input.password == this.input.passwordConfirm))) {
|
||||
console.log('Authenticated: Checking with Backend');
|
||||
fetch("http://localhost:5000/api/users/create", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: this.input.username,
|
||||
password: this.input.password,
|
||||
email: "asdf",
|
||||
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");
|
||||
} else {
|
||||
console.log('Username and Password cannot be empty');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in a new issue