From ac113b3b133d149b06596dda21e2612a2a1ffaba Mon Sep 17 00:00:00 2001 From: adri Date: Sun, 30 Dec 2018 19:53:28 +0100 Subject: [PATCH] add js input rules --- index.php | 10 ++++---- post.php | 24 +++++++++--------- script.js | 73 +++++++++++++++++++++++++++++++++++++++++-------------- style.css | 14 +++++++++++ 4 files changed, 86 insertions(+), 35 deletions(-) diff --git a/index.php b/index.php index 58117e7..ec19f63 100755 --- a/index.php +++ b/index.php @@ -43,15 +43,15 @@ $reponse = $bdd->query('SELECT * FROM projetphp'); ?> - + - + - + - + - + prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `mot_de_passe` = :pw, `security_level` = :sl WHERE `projetphp`.`login` = :login'); $req->execute(array( - 'datene' => $_POST["datene"], - 'email' => $_POST["email"], - 'pw' => md5($_POST["pw"]), - 'sl' => $_POST["sl"], - 'login' => $_POST["login"], + 'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'), + 'email' => htmlspecialchars($_POST["email"], ENT_QUOTES, 'UTF-8'), + 'pw' => md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8')), + 'sl' => htmlspecialchars($_POST["sl"], ENT_QUOTES, 'UTF-8'), + 'login' => htmlspecialchars($_POST["login"], ENT_QUOTES, 'UTF-8'), )); $ret["return"] = true; - $ret["pw"] = md5($_POST["pw"]); + $ret["pw"] = md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8')); } else { $req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `security_level` = :sl WHERE `projetphp`.`login` = :login'); $req->execute(array( - 'datene' => $_POST["datene"], - 'email' => $_POST["email"], - 'sl' => $_POST["sl"], - 'login' => $_POST["login"], + 'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'), + 'email' => htmlspecialchars($_POST["email"], ENT_QUOTES, 'UTF-8'), + 'sl' => htmlspecialchars($_POST["sl"], ENT_QUOTES, 'UTF-8'), + 'login' => htmlspecialchars($_POST["login"], ENT_QUOTES, 'UTF-8'), )); $ret["return"] = true; - $ret["pw"] = $_POST["pw"]; + $ret["pw"] = htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8'); } else; diff --git a/script.js b/script.js index 566bd54..b0e829f 100644 --- a/script.js +++ b/script.js @@ -1,11 +1,40 @@ $(function() { + passwordPatern=/^[a-zA-Z0-9]{8,16}$/; + loginPatern=/^[a-z]{8,16}$/ + mailPatern=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;//https://emailregex.com/ +$("#allRecord").on("keyup", ".pw input", function(){ + if(passwordPatern.test($(this).val()) || $(this).val() == "") + { + $(this).css("background-color", ""); + $('div', $(this).parent()).css("display", "none"); + } + else + { + $(this).css("background-color", "red"); + $('div', $(this).parent()).css("display", "block"); + } +}); +$("#allRecord").on("keyup", ".email input", function(){ + if(mailPatern.test($(this).val())) + { + $(this).css("background-color", ""); + $('div', $(this).parent()).css("display", "none"); + } + else + { + $(this).css("background-color", "red"); + $('div', $(this).parent()).css("display", "block"); + } +}); + + /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~TR TO EDIT~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ $("#allRecord").on("click", ".editUser", function() { $(this).toggleClass('fa-edit fa-check'); $(this).toggleClass('editUser confirmEditUser'); - for(i=0; i<$("td", $(this).parent().parent()).length-1;i++) + for(i=1; i<$("td", $(this).parent().parent()).length-1;i++) { j= $($("td", $(this).parent().parent())[i]); className = j.attr('class'); @@ -26,6 +55,10 @@ $(function() { else if (j.attr('class') == "datene") inputOptions += 'type="date" ' j.html(''); + if(className=="pw") + { + j.append("
le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9
") + } } } }); @@ -48,6 +81,8 @@ $(function() { className = j.attr('class'); if(className == "pw" && data === true) value = $('input,select', j).data("oldpw"); + else if(className=="login") + value = ltrim(j.html()); else value = $('input,select', j).val(); dataToSend[className] = value; @@ -56,7 +91,7 @@ $(function() { try { if(data.return == true) { - for(i=0; i