mirror of
https://gitlab.com/little-lines/frontend.git
synced 2024-11-25 16:46:53 +00:00
create login and register functionable
This commit is contained in:
parent
eb55b258d9
commit
004c9a697c
2 changed files with 32 additions and 3 deletions
|
@ -47,6 +47,32 @@ export default {
|
||||||
login() {
|
login() {
|
||||||
if (this.input.username !== '' && this.input.password !== '') {
|
if (this.input.username !== '' && this.input.password !== '') {
|
||||||
console.log('Authenticated: Checking with Backend');
|
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.loginStatus);
|
||||||
|
sessionStorage.setItem('current_user', data.userName);
|
||||||
|
this.$router.push({ name: 'home' });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
// Handle the error, e.g., display an error message to the user
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('Username and Password cannot be empty');
|
console.log('Username and Password cannot be empty');
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,13 @@
|
||||||
console.log('Authenticated: Checking with Backend');
|
console.log('Authenticated: Checking with Backend');
|
||||||
fetch("http://localhost:5000/api/users/create", {
|
fetch("http://localhost:5000/api/users/create", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
username: username,
|
username: this.input.username,
|
||||||
password: password,
|
password: this.input.password,
|
||||||
email: "",
|
email: "asdf",
|
||||||
isGoogleAccount: false
|
isGoogleAccount: false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue