Files
esauth-2024/public/html/telegram-callback.html
T

33 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script defer>
function bodyLoad() {
if (localStorage.getItem("token") != null) checkToken(localStorage.getItem("token"));
else window.location.href = window.location.href.replace("telegram-callback", "telegram-callback-process")
}
function checkToken(token) {
console.log("Checking token...")
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://auth.easystartup.su/api/user/self', true);
xhr.setRequestHeader('Authorization', `Bearer ${token}`);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if(xhr.status == 200) {
console.log("Status 200")
let ans = JSON.parse(xhr.responseText)
if(ans.telegram_id == "") window.location.href = window.location.href.replace("telegram-callback", "telegram-callback-process") + "&usertoken=" + token
else window.location.href = window.location.href.replace("telegram-callback", "telegram-callback-process")
} else window.location.href = window.location.href.replace("telegram-callback", "telegram-callback-process")
};
xhr.onerror = function() {
console.log('Network error');
};
xhr.send();
}
</script>
</head>
<body onload="bodyLoad()"><</body>