Define variables globally
This commit is contained in:
parent
b230e39e10
commit
403cc8ed53
|
@ -1,4 +1,5 @@
|
||||||
<html><head>
|
<html>
|
||||||
|
<head>
|
||||||
<title>Login - Burgernotes</title>
|
<title>Login - Burgernotes</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
@ -7,6 +8,8 @@
|
||||||
<script src="../static/js/hash-wasm.js"></script>
|
<script src="../static/js/hash-wasm.js"></script>
|
||||||
<link rel="icon" href="../static/svg/favicon.svg">
|
<link rel="icon" href="../static/svg/favicon.svg">
|
||||||
<script>
|
<script>
|
||||||
|
var client_id, redirect_uri, response_type, state, code, codemethod, secret_key, expires;
|
||||||
|
|
||||||
if (window.location.href.endsWith('/index.html')) {
|
if (window.location.href.endsWith('/index.html')) {
|
||||||
if (window.location.origin !== null) {
|
if (window.location.origin !== null) {
|
||||||
var currentUrl = window.location.href;
|
var currentUrl = window.location.href;
|
||||||
|
@ -14,6 +17,52 @@
|
||||||
window.location.href = newUrl;
|
window.location.href = newUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localStorage.getItem("DONOTSHARE-secretkey") === null) {
|
||||||
|
window.location.replace("/login" + window.location.search)
|
||||||
|
document.body.innerHTML = "Redirecting..."
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
var statusBox = document.getElementById("statusBox");
|
||||||
|
|
||||||
|
// Get URL parameters
|
||||||
|
if (urlParams.has('client_id')) {
|
||||||
|
client_id = urlParams.get('client_id');
|
||||||
|
statusBox.textContent = "Would you like to allow " + client_id + " to access your user information?";
|
||||||
|
redirect_uri = urlParams.get('redirect_uri');
|
||||||
|
response_type = urlParams.get('response_type');
|
||||||
|
} else {
|
||||||
|
window.location.replace("/dashboard");
|
||||||
|
document.body.innerHTML = "Redirecting..."
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
|
state = urlParams.has('state') ? urlParams.get('state') : "none";
|
||||||
|
|
||||||
|
if (urlParams.has('code_challenge')) {
|
||||||
|
code = urlParams.get('code_challenge');
|
||||||
|
codemethod = urlParams.get('code_challenge_method');
|
||||||
|
} else {
|
||||||
|
code = "none";
|
||||||
|
codemethod = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get DONOTSHARE-secretkey from localStorage
|
||||||
|
secret_key = localStorage.getItem("DONOTSHARE-secretkey");
|
||||||
|
var now = new Date();
|
||||||
|
var expireTime = now.getTime() + (21 * 1000); // 21 seconds from now
|
||||||
|
expires = new Date(expireTime).toUTCString();
|
||||||
|
});
|
||||||
|
|
||||||
|
function oauth() {
|
||||||
|
document.cookie = "key=" + secret_key + "; expires=" + expires + "; path=/";
|
||||||
|
|
||||||
|
// Send data to example.org using POST request
|
||||||
|
window.location.replace("/api/auth?client_id=" + client_id + "&redirect_uri=" + redirect_uri + "&code_challenge_method=" + codemethod + "&code_challenge=" + code + "&state=" + state);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@ -29,55 +78,6 @@
|
||||||
<button onclick="window.location.replace('https://www.hectabit.org');" style="margin: 0;width: 100%;margin-left: 2.5px;">Deny</button>
|
<button onclick="window.location.replace('https://www.hectabit.org');" style="margin: 0;width: 100%;margin-left: 2.5px;">Deny</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
</body>
|
||||||
if (localStorage.getItem("DONOTSHARE-secretkey") === null) {
|
|
||||||
window.location.replace("/login" + window.location.search)
|
|
||||||
document.body.innerHTML = "Redirecting..."
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
</html>
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
var statusBox = document.getElementById("statusBox");
|
|
||||||
|
|
||||||
// Get URL parameters
|
|
||||||
if (urlParams.has('client_id')) {
|
|
||||||
var client_id = urlParams.get('client_id');
|
|
||||||
statusBox.textContent = "Would you like to allow " + client_id + " to access your user infomation?"
|
|
||||||
var redirect_uri = urlParams.get('redirect_uri');
|
|
||||||
var response_type = urlParams.get('response_type');
|
|
||||||
} else {
|
|
||||||
window.location.replace("/dashboard");
|
|
||||||
document.body.innerHTML = "Redirecting..."
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (urlParams.has('state')) {
|
|
||||||
var state = urlParams.get('state');
|
|
||||||
} else {
|
|
||||||
state = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (urlParams.has('code_challenge')) {
|
|
||||||
code = urlParams.get('code_challenge');
|
|
||||||
codemethod = urlParams.get('code_challenge_method');
|
|
||||||
} else {
|
|
||||||
code = "none"
|
|
||||||
codemethod = "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get DONOTSHARE-secretkey from localStorage
|
|
||||||
var secret_key = localStorage.getItem("DONOTSHARE-secretkey");
|
|
||||||
var now = new Date();
|
|
||||||
var expireTime = now.getTime() + (21 * 1000); // 21 seconds from now
|
|
||||||
var expires = new Date(expireTime).toUTCString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function oauth() {
|
|
||||||
document.cookie = "key=" + secret_key + "; expires=" + expires + "; path=/";
|
|
||||||
|
|
||||||
// Send data to example.org using POST request
|
|
||||||
window.location.replace("/api/auth?client_id=" + client_id + "&redirect_uri=" + redirect_uri + "&code_challenge_method=" + codemethod + "&code_challenge=" + code + "&state=" + state)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body></html>
|
|
||||||
|
|
Reference in New Issue