This repository has been archived on 2022-10-26. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
diswho/www/index.html
2021-06-24 22:04:38 +02:00

71 lines
No EOL
2.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8">
<title>DisWho</title>
<style>
.app {
font-family: sans-serif;
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
color: #ABB2BF;
background-color: #282C34;
}
.app__title {
font-size: 1rem;
opacity: 0.5;
}
.app__status {
font-size: 2.5rem;
}
</style>
<script>
window.addEventListener('DOMContentLoaded', async () => {
const
status = document.querySelector('.app__status'),
button = document.createElement('button'),
script = document.createElement('script'),
returnUrl = new URLSearchParams(window.location.search).get('returnUrl'),
{ publicKey } = await (await fetch('/captcha/credentials')).json();
button.classList.add('g-recaptcha');
button.setAttribute('data-sitekey', publicKey);
button.setAttribute('data-action', 'submit');
script.setAttribute('src', `https://www.google.com/recaptcha/api.js?render=${publicKey}`);
script.addEventListener('load', async () => grecaptcha.ready(async () => {
button.addEventListener('click', async () => {
document.body.removeChild(button);
status.textContent = 'Generating captcha';
const token = await grecaptcha.execute(publicKey);
status.textContent = 'Validating captcha';
const {
success,
jwt
} = await (await fetch(`/captcha/validate?token=${token}`)).json();
if(success){
status.textContent = 'Captcha validated';
if(returnUrl)
window.location.replace(`${returnUrl}?diswhoJwt=${jwt}`);
}
else
status.textContent = 'Captcha failed';
});
document.body.appendChild(button);
button.click();
}));
document.body.appendChild(script);
});
</script>
</head>
<body class="app">
<h1 class="app__title">DisWho</h1>
<p class="app__status">Loading</p>
</body>
</html>