mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-30 01:21:54 +08:00
2fa code in the login page
This commit is contained in:
@@ -33,7 +33,7 @@ export function main() {
|
||||
initWindowManager();
|
||||
|
||||
tools.el.setOnClick($("login-button"), __login);
|
||||
$("user-input").onkeyup = $("passwd-input").onkeyup = function(event) {
|
||||
$("user-input").onkeyup = $("passwd-input").onkeyup = $("code-input").onkeyup = function(event) {
|
||||
if (event.code === "Enter") {
|
||||
event.preventDefault();
|
||||
$("login-button").click();
|
||||
@@ -49,21 +49,21 @@ function __login() {
|
||||
if (user.length === 0) {
|
||||
$("user-input").focus();
|
||||
} else {
|
||||
let passwd = $("passwd-input").value;
|
||||
let passwd = $("passwd-input").value + $("code-input").value;
|
||||
let body = `user=${encodeURIComponent(user)}&passwd=${encodeURIComponent(passwd)}`;
|
||||
let http = tools.makeRequest("POST", "/api/auth/login", function() {
|
||||
if (http.readyState === 4) {
|
||||
if (http.status === 200) {
|
||||
document.location.href = "/";
|
||||
} else if (http.status === 403) {
|
||||
wm.error("Invalid username or password").then(__tryAgain);
|
||||
wm.error("Invalid credentials").then(__tryAgain);
|
||||
} else {
|
||||
let error = "";
|
||||
if (http.status === 400) {
|
||||
try { error = JSON.parse(http.responseText)["result"]["error"]; } catch (_) { /* Nah */ }
|
||||
}
|
||||
if (error === "ValidatorError") {
|
||||
wm.error("Invalid username or password characters").then(__tryAgain);
|
||||
wm.error("Invalid characters in credentials").then(__tryAgain);
|
||||
} else {
|
||||
wm.error("Login error:<br>", http.responseText).then(__tryAgain);
|
||||
}
|
||||
@@ -77,11 +77,13 @@ function __login() {
|
||||
function __setEnabled(enabled) {
|
||||
tools.el.setEnabled($("user-input"), enabled);
|
||||
tools.el.setEnabled($("passwd-input"), enabled);
|
||||
tools.el.setEnabled($("code-input"), enabled);
|
||||
tools.el.setEnabled($("login-button"), enabled);
|
||||
}
|
||||
|
||||
function __tryAgain() {
|
||||
__setEnabled(true);
|
||||
$("passwd-input").focus();
|
||||
$("passwd-input").select();
|
||||
let el = ($("code-input").value.length ? $("code-input") : $("passwd-input"));
|
||||
el.focus();
|
||||
el.select();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user