streams/view/tpl/totp.tpl

61 lines
1.5 KiB
Smarty
Raw Normal View History

<script type="text/javascript">
2023-03-04 05:44:40 +00:00
let totp_success_msg = '{{$success}}';
let totp_fail_msg = '{{$fail}}';
let totp_maxfails_msg = '{{$maxfails}}';
let try_countdown = 3;
2023-03-04 04:43:05 +00:00
$(window).on("load", function() {
totp_clear();
2023-03-04 04:43:05 +00:00
});
function totp_clear() {
2023-03-04 04:43:05 +00:00
let box = document.getElementById("totp-code");
box.value = "";
box.focus();
2023-03-04 04:43:05 +00:00
}
function totp_verify() {
var code = document.getElementById("totp-code").value;
2023-03-04 05:44:40 +00:00
$.post("totp_check", {totp_code: code},
function(resp) {
2023-03-04 05:44:40 +00:00
let report = document.getElementById("feedback");
let box = document.getElementById("totp-code");
if (resp['status']) {
report.innerHTML = "<b>" + totp_success_msg + "</b>";
window.location = "/";
2023-03-04 05:44:40 +00:00
}
else {
try_countdown -= 1;
if (try_countdown < 1) {
report.innerHTML = totp_maxfails_msg;
window.location = "/logout";
2023-03-04 09:36:54 +00:00
}
else {
report.innerHTML = totp_fail_msg;
totp_clear();
}
2023-03-04 09:36:54 +00:00
}
}
);
2023-03-04 05:44:40 +00:00
}
function hitkey(ev) {
if (ev.which == 13) totp_verify();
2023-03-04 05:44:40 +00:00
}
</script>
2023-03-04 09:36:54 +00:00
<div class="generic-content-wrapper">
<div class="section-content-tools-wrapper">
<h3 style="text-align: center;">{{$header}}</h3>
<div>{{$desc}}</div>
2023-03-08 11:33:33 +00:00
<br>
2023-03-04 09:36:54 +00:00
<div class="form-group">
<input type="text" class="form-control" style="width: 10em" id="totp-code" onkeydown="hitkey(event)"/>
<div id="feedback"></div>
</div>
2023-03-08 11:33:33 +00:00
<br>
2023-03-04 09:36:54 +00:00
<div>
<input type="button" class="btn btn-primary" value={{$submit}} onclick="totp_verify()"/>
</div>
</div>
</div>