35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
let baseUrl = "http://localhost:8000"
|
|
|
|
document.getElementById("submitBtn").addEventListener('click', function(e) {
|
|
let code = document.getElementById("code").value;
|
|
console.log("Clicked: " + code);
|
|
|
|
const path = window.location.pathname;
|
|
const parts = path.split("/");
|
|
//const user = parts.pop();
|
|
|
|
const user = "tracey"
|
|
fetch(baseUrl + "/api/verify/" + user, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': "Basic " + code,
|
|
}
|
|
}).then(response => response.json())
|
|
.then(data => {
|
|
let statusText = document.getElementById("status");
|
|
console.log(data);
|
|
statusText.classList.remove("hidden");
|
|
if (data.status === 404) {
|
|
// Not found
|
|
statusText.innerText = "User with that code not found";
|
|
} else if (data.status === 200) {
|
|
// Display found and redirect to baseUrl/u/user/info with auth token
|
|
statusText.innerText = "User found, redirecting...";
|
|
window.location.replace(baseUrl + "/u/" + user + "/info")
|
|
} else {
|
|
// Error
|
|
statusText.innerText = "Error, please send this to Steven to be fixed. Error: " + data.error;
|
|
}
|
|
})
|
|
}) |