From 54ec4fa28a7170f1e92693858a995e90797b0183 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 22 Sep 2018 09:23:59 +0300 Subject: [PATCH 1/4] attr() is undefined when elem doesnt have it --- code/html/custom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/html/custom.js b/code/html/custom.js index de0c5af7..2b37998c 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -359,7 +359,7 @@ function sendConfig(data) { function setOriginalsFromValues(force) { var force = (true === force); $("input,select").each(function() { - var initial = (null === $(this).attr("original")); + var initial = (undefined === $(this).attr("original")); if (force || initial) { $(this).attr("original", $(this).val()); } From 7a8949fd249520d03d716bfaaee13172c98120ee Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 22 Sep 2018 09:27:29 +0300 Subject: [PATCH 2/4] Check if password is required before showing alert Show alert if no input on #password page Do not fail with empty password when on #layout Fix password selector --- code/html/custom.js | 42 ++++++++++++++++++++++++++++++------------ code/html/index.html | 16 ++++++++-------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/code/html/custom.js b/code/html/custom.js index 2b37998c..ba542dd6 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -164,21 +164,35 @@ function validatePassword(password) { ); } -function validateForm(form) { +function validateFormPasswords(form) { + var passwords = $("input[name='adminPass1'],input[name='adminPass2']", form); + var adminPass1 = passwords.first().val(), + adminPass2 = passwords.last().val(); + + var formValidity = passwords.first()[0].checkValidity(); + if (formValidity && (adminPass1.length === adminPass2.length === 0)) { + return true; + } + + var validPass1 = validatePassword(adminPass1), + validPass2 = validatePassword(adminPass2); - // password - var adminPass1 = $("input[name='adminPass']", form).first().val(); - if (!validatePassword(adminPass1)) { + if (formValidity && validPass1 && validPass2) { + return true; + } + + if (!formValidity || (adminPass1.length > 0 && !validPass1)) { alert("The password you have entered is not valid, it must be 8..63 characters and have at least 1 lowercase and 1 uppercase / number!"); - return false; } - var adminPass2 = $("input[name='adminPass_confirm']", form).last().val(); if (adminPass1 !== adminPass2) { alert("Passwords are different!"); - return false; } + return false; +} + +function validateFormHostname(form) { // RFCs mandate that a hostname's labels may contain only // the ASCII letters 'a' through 'z' (case-insensitive), // the digits '0' through '9', and the hyphen. @@ -196,13 +210,17 @@ function validateForm(form) { return true; } - if (!re_hostname.test(hostname.val())) { - alert("Hostname cannot be empty and may only contain the ASCII letters ('A' through 'Z' and 'a' through 'z'), the digits '0' through '9', and the hyphen ('-')! They can neither start or end with an hyphen."); - return false; + if (re_hostname.test(hostname.val())) { + return true; } - return true; + alert("Hostname cannot be empty and may only contain the ASCII letters ('A' through 'Z' and 'a' through 'z'), the digits '0' through '9', and the hyphen ('-')! They can neither start or end with an hyphen."); + return false; +} + +function validateForm(form) { + return validateFormPasswords(form) && validateFormHostname(form); } function getValue(element) { @@ -235,7 +253,7 @@ function addValue(data, name, value) { ]; - // join both adminPass and ..._confirm + // join both adminPass 1 and 2 if (name.startsWith("adminPass")) { name = "adminPass"; } diff --git a/code/html/index.html b/code/html/index.html index bdf1e7bf..a852d1ef 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -28,7 +28,7 @@
-
+
@@ -41,14 +41,14 @@
- - + +
- - + +
@@ -62,7 +62,7 @@
- +
@@ -533,10 +533,10 @@
- +
- +
From 9cdf59f1b2a18a69d0f24ef6c9e3d870488d1a22 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 22 Sep 2018 10:46:10 +0300 Subject: [PATCH 3/4] Fix selector order --- code/html/custom.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/html/custom.css b/code/html/custom.css index af494464..97d88f5e 100644 --- a/code/html/custom.css +++ b/code/html/custom.css @@ -94,11 +94,11 @@ div.center { display: none; } -.content #password { +#password .content { margin: 0 auto; } -.content #layout { +#layout .content { margin: 0; } From d69c30aa6153d2fd79d9b3a936102235589f86cd Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 29 Sep 2018 06:55:31 +0300 Subject: [PATCH 4/4] Use specific function to check form --- code/html/custom.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/html/custom.js b/code/html/custom.js index ba542dd6..e651ff5c 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -205,8 +205,7 @@ function validateFormHostname(form) { var re_hostname = new RegExp('^(?!-)[A-Za-z0-9-]{0,30}[A-Za-z0-9]$'); var hostname = $("input[name='hostname']", form); - var hasChanged = ("true" === hostname.attr("hasChanged")); - if (!hasChanged) { + if ("true" !== hostname.attr("hasChanged")) { return true; } @@ -496,7 +495,7 @@ function doUpgrade() { function doUpdatePassword() { var form = $("#formPassword"); - if (validateForm(form)) { + if (validateFormPasswords(form)) { sendConfig(getData(form)); } return false;