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; } diff --git a/code/html/custom.js b/code/html/custom.js index de0c5af7..e651ff5c 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. @@ -191,18 +205,21 @@ function validateForm(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; } - 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 +252,7 @@ function addValue(data, name, value) { ]; - // join both adminPass and ..._confirm + // join both adminPass 1 and 2 if (name.startsWith("adminPass")) { name = "adminPass"; } @@ -359,7 +376,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()); } @@ -478,7 +495,7 @@ function doUpgrade() { function doUpdatePassword() { var form = $("#formPassword"); - if (validateForm(form)) { + if (validateFormPasswords(form)) { sendConfig(getData(form)); } return false; 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 @@
- +
- +