113 lines
4.9 KiB
HTML
113 lines
4.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
|
<link th:href="@{/styles/authenticate.css}" rel="stylesheet" />
|
|
</head>
|
|
|
|
<body class="center-screen">
|
|
|
|
<h1 th:text="|Dir wurde ein Code an ${name} gesendet!|"></h1>
|
|
<h1>Nicht wundern das kann ein wenig dauern!</h1>
|
|
<h1 id="time_remain" class="end" th:text="${codeTime}"></h1>
|
|
<h2>Bitte gebe den Authentifizierungscode ein</h2>
|
|
<form action="#" id="passForm" th:action="@{/vote}" method="post">
|
|
<input id="voterName" type="hidden" name="name" th:value="${name}" />
|
|
<input id="authCode" type="hidden" name="code" value="" />
|
|
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}" autofocus>
|
|
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
|
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
|
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
|
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
|
<input type="text" placeholder="•" class="passInput" name="pass[]" maxlength="1" autocomplete="off" required pattern="\d{1}">
|
|
</form>
|
|
<button class="submitButton" id="signup_button" onclick="getCode()">Abstimmen</button>
|
|
|
|
|
|
<form action="#" th:action="@{/newCode}" method="post">
|
|
<input id="voterName" type="hidden" name="name" th:value="${name}" />
|
|
<button class="newCode">Neuen Code anfordern</button>
|
|
</form>
|
|
|
|
|
|
<div th:if="${codeExpired}">
|
|
<h2 class="errorCode">Der Code ist nicht mehr gültig!</h2>
|
|
</div>
|
|
|
|
<div th:if="${codeFalse}">
|
|
<h2 class="errorCode">Der eingegebene Code ist falsch</h2>
|
|
</div>
|
|
|
|
<script>
|
|
const $inp = $(".passInput");
|
|
|
|
$inp.on({
|
|
paste(ev) { // Handle Pasting
|
|
const clip = ev.originalEvent.clipboardData.getData('text').trim();
|
|
// Allow numbers only
|
|
if (!/\d{6}/.test(clip)) return ev.preventDefault(); // Invalid. Exit here
|
|
// Split string to Array or characters
|
|
const s = [...clip];
|
|
// Populate inputs. Focus last input.
|
|
$inp.val(i => s[i]).eq(5).focus();
|
|
},
|
|
input(ev) { // Handle typing
|
|
|
|
const i = $inp.index(this);
|
|
if (this.value) $inp.eq(i + 1).focus();
|
|
},
|
|
keydown(ev) { // Handle Deleting
|
|
|
|
const i = $inp.index(this);
|
|
if (!this.value && ev.key === "Backspace" && i) $inp.eq(i - 1).focus();
|
|
}
|
|
});
|
|
|
|
function getCode() {
|
|
groupInputs = document.querySelectorAll(".passInput");
|
|
var code = "";
|
|
groupInputs.forEach(input => {
|
|
console.log("Input: " + input.value);
|
|
code += input.value;
|
|
});
|
|
console.log("Code: " + code);
|
|
output = document.getElementById("authCode");
|
|
output.value = code;
|
|
document.getElementById("passForm").submit();
|
|
}
|
|
|
|
function updateCounter(time) {
|
|
const zeroPad = (num, places) => String(num).padStart(places, '0')
|
|
|
|
// Show time remaining now.
|
|
showTimeRemaining();
|
|
|
|
var dateFuture = time;
|
|
console.log(dateFuture);
|
|
|
|
// Set a timer to update the displayed clock every 1000 milliseconds.
|
|
var updateTimeLoop = setInterval(showTimeRemaining, 1000);
|
|
|
|
function showTimeRemaining() {
|
|
var dateNow = Date.now();
|
|
var days = zeroPad(Math.floor((dateFuture - dateNow) / (1000 * 60 * 60 * 24)), 2);
|
|
var hours = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24) / (1000 * 60 * 60)), 2);
|
|
var mins = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60) / (1000 * 60)), 2);
|
|
var secs = zeroPad(Math.floor(((dateFuture - dateNow) - days * 1000 * 60 * 60 * 24 - hours * 1000 * 60 * 60 - mins * 1000 * 60) / 1000), 2);
|
|
document.getElementById("time_remain").innerHTML = "Der Code gilt noch für " + mins + ":" + secs;
|
|
if (hours + mins + secs == 0) {
|
|
document.getElementById("time_remain").innerHTML = "Der Code ist abgelaufen";
|
|
}
|
|
}
|
|
}
|
|
|
|
updateCounter(document.getElementById("time_remain").innerHTML);
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
</html> |