2022-04-19 17:24:07 +00:00
|
|
|
{% extends "base_login_page.html" %}
|
|
|
|
{% block content %}
|
|
|
|
|
2022-04-20 09:59:16 +00:00
|
|
|
<style>
|
|
|
|
#otp input {
|
|
|
|
padding-left: 0px;
|
|
|
|
padding-right: 0px;
|
|
|
|
}
|
2022-04-20 10:06:56 +00:00
|
|
|
|
2022-04-20 09:59:16 +00:00
|
|
|
</style>
|
|
|
|
|
2022-04-19 17:24:07 +00:00
|
|
|
<div>
|
2022-11-11 11:26:02 +00:00
|
|
|
<p>Please open one of your registered authenticator app, generate a new code and enter it here:</p>
|
|
|
|
<form id="totp_form" method="post">
|
2022-04-20 10:06:56 +00:00
|
|
|
<input type="hidden" id="code" name="code"/>
|
2022-04-19 17:24:07 +00:00
|
|
|
<div class="form-group">
|
2022-04-20 09:59:16 +00:00
|
|
|
<div id="otp" class="inputs d-flex flex-row justify-content-center mt-2">
|
2022-11-12 17:04:27 +00:00
|
|
|
<input class="m-2 text-center form-control rounded" type="text" id="i1" maxlength="6" autofocus/>
|
|
|
|
<input class="m-2 text-center form-control rounded" type="text" id="i2" maxlength="6"/>
|
|
|
|
<input class="m-2 text-center form-control rounded" type="text" id="i3" maxlength="6"/>
|
|
|
|
<input class="m-2 text-center form-control rounded" type="text" id="i4" maxlength="6"/>
|
|
|
|
<input class="m-2 text-center form-control rounded" type="text" id="i5" maxlength="6"/>
|
|
|
|
<input class="m-2 text-center form-control rounded" type="text" id="i6" maxlength="6"/>
|
2022-04-20 09:59:16 +00:00
|
|
|
</div>
|
2022-04-19 17:24:07 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div style="margin-top: 10px;">
|
2022-04-20 10:06:56 +00:00
|
|
|
<a href="/2fa_auth?force_display=true&redirect={{ _p.redirect_uri.get_encoded() }}">Sign in using another factor</a><br/>
|
2022-04-19 17:24:07 +00:00
|
|
|
<a href="/logout">Sign out</a>
|
|
|
|
</div>
|
|
|
|
|
2022-04-20 09:59:16 +00:00
|
|
|
<script>
|
|
|
|
function OTPInput() {
|
2022-11-11 11:26:02 +00:00
|
|
|
// Set form destination
|
|
|
|
document.getElementById("totp_form").action = location.href;
|
|
|
|
|
2022-04-20 09:59:16 +00:00
|
|
|
const inputs = document.querySelectorAll('#otp > *[id]');
|
|
|
|
for (let i = 0; i < inputs.length; i++) {
|
|
|
|
// Reset form on init
|
|
|
|
inputs[i].value = "";
|
2022-04-20 15:52:32 +00:00
|
|
|
}
|
2022-04-20 09:59:16 +00:00
|
|
|
|
2022-11-12 17:04:27 +00:00
|
|
|
|
|
|
|
function getCurrIndex() {
|
|
|
|
for(const [i, input] of inputs.entries()) {
|
|
|
|
if(input.value === "")
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-20 09:59:16 +00:00
|
|
|
|
2022-04-20 15:52:32 +00:00
|
|
|
document.addEventListener('keydown', (event) => {
|
2022-11-12 17:04:27 +00:00
|
|
|
let currIndex = getCurrIndex();
|
2022-04-20 15:52:32 +00:00
|
|
|
if (event.key === "Backspace") {
|
|
|
|
if (inputs[currIndex].value != "") {
|
|
|
|
inputs[currIndex].value = '';
|
|
|
|
} else if (currIndex > 0) {
|
|
|
|
inputs[currIndex - 1].value = "";
|
|
|
|
inputs[currIndex - 1].focus();
|
|
|
|
currIndex--;
|
2022-04-20 09:59:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 17:04:27 +00:00
|
|
|
event.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function handleChange(index) {
|
|
|
|
const input = inputs[index];
|
|
|
|
|
|
|
|
// Remove non-numeric values from input
|
|
|
|
const correctValue = input.value.replace(/[^0-9]/g, "");
|
|
|
|
if (correctValue !== input.value)
|
|
|
|
input.value = correctValue;
|
|
|
|
|
|
|
|
if(correctValue.length == 0) {
|
|
|
|
input.focus();
|
2022-04-20 15:52:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-11-12 17:04:27 +00:00
|
|
|
|
|
|
|
input.value = correctValue.substring(0, 1);
|
2022-04-20 15:52:32 +00:00
|
|
|
|
2022-11-12 17:04:27 +00:00
|
|
|
if (index === 5) {
|
|
|
|
submitCode();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inputs[index + 1].value = correctValue.substring(1) + inputs[index + 1].value;
|
|
|
|
handleChange(index + 1);
|
2022-04-20 15:52:32 +00:00
|
|
|
}
|
2022-11-12 17:04:27 +00:00
|
|
|
}
|
2022-04-20 09:59:16 +00:00
|
|
|
|
2022-11-12 17:04:27 +00:00
|
|
|
// Listen to event on all inputs
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
inputs[i].addEventListener("change", () => handleChange(i))
|
|
|
|
inputs[i].addEventListener("keyup", () => handleChange(i))
|
|
|
|
}
|
2022-04-20 09:59:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitCode() {
|
|
|
|
const code = [...document.querySelectorAll('#otp > *[id]')]
|
|
|
|
.map((i) => i.value)
|
|
|
|
.join("");
|
|
|
|
|
|
|
|
document.getElementById("code").value = code;
|
|
|
|
document.getElementById("totp_form").submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", () => OTPInput());
|
|
|
|
</script>
|
|
|
|
|
2022-04-19 17:24:07 +00:00
|
|
|
{% endblock content %}
|