Change Auth Code
This commit is contained in:
parent
33026f6a9e
commit
12ba1760e7
@ -1,6 +1,4 @@
|
|||||||
let loginb = document.getElementById("loginb");
|
let loginb = document.getElementById("loginb");
|
||||||
let _username;
|
|
||||||
let _password;
|
|
||||||
|
|
||||||
loginb.addEventListener("click", validateLogin);
|
loginb.addEventListener("click", validateLogin);
|
||||||
|
|
||||||
@ -36,32 +34,38 @@ function validatePass() {
|
|||||||
|
|
||||||
function validateLogin() {
|
function validateLogin() {
|
||||||
if(validateName() && validatePass()) {
|
if(validateName() && validatePass()) {
|
||||||
getLD();
|
getAuth();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLD() {
|
async function getAuth() {
|
||||||
_username = document.getElementById("username").value;
|
let _username = document.getElementById("username").value;
|
||||||
_mpassword = document.getElementById("password").value;
|
let _password = document.getElementById("password").value;
|
||||||
let loginData = {
|
try {
|
||||||
user_name: _username,
|
const response = await fetch('http://127.0.0.1:5000/', {
|
||||||
password: _password
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
user_name: _username,
|
||||||
|
password: _password
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!response.ok) {
|
||||||
|
throw new Error('Connection was not Ok!');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
const token = data.token;
|
||||||
|
|
||||||
|
console.log(`Got token: ${token}`)
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error', error);
|
||||||
}
|
}
|
||||||
fetch('http://127.0.0.1:5000', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(loginData)
|
|
||||||
})
|
|
||||||
.then(res => {
|
|
||||||
return res.json()
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
handleAuthRes(data);
|
|
||||||
})
|
|
||||||
.catch(error => console.log(`You have ${error}`))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAuthRes(data) {
|
function handleAuthRes(data) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user