32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
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();
|
|
|
|
fetch("/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("/u/" + user + "/info?token=" + data.token);
|
|
} else {
|
|
// Error
|
|
statusText.innerText = "Error, please send this to Steven to be fixed. Error: " + data.error;
|
|
}
|
|
})
|
|
}) |