add js input rules
This commit is contained in:
parent
f512c2e0c4
commit
ac113b3b13
10
index.php
10
index.php
|
@ -43,15 +43,15 @@ $reponse = $bdd->query('SELECT * FROM projetphp');
|
||||||
?>
|
?>
|
||||||
<tr class="record">
|
<tr class="record">
|
||||||
<td class="login">
|
<td class="login">
|
||||||
<?= htmlspecialchars($data["login"]) ?></td>
|
<?= ($data["login"]) ?></td>
|
||||||
<td class="datene">
|
<td class="datene">
|
||||||
<?= htmlspecialchars($data["date_naissance"]) ?></td>
|
<?= ($data["date_naissance"]) ?></td>
|
||||||
<td class="email">
|
<td class="email">
|
||||||
<?= htmlspecialchars($data["e_mail"]) ?></td>
|
<?= ($data["e_mail"]) ?></td>
|
||||||
<td class="pw">
|
<td class="pw">
|
||||||
<?= htmlspecialchars($data["mot_de_passe"]) ?></td>
|
<?= ($data["mot_de_passe"]) ?></td>
|
||||||
<td class="sl">
|
<td class="sl">
|
||||||
<?= htmlspecialchars($data["security_level"]) ?></td>
|
<?= ($data["security_level"]) ?></td>
|
||||||
<td><i class="fas fa-edit click editUser"></i><i class="fas fa-trash-alt click delUser"></i></td>
|
<td><i class="fas fa-edit click editUser"></i><i class="fas fa-trash-alt click delUser"></i></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
|
|
24
post.php
24
post.php
|
@ -9,30 +9,30 @@ try {
|
||||||
}
|
}
|
||||||
//UPDATE `projetphp` SET `security_level` = '6' WHERE `projetphp`.`login` = 'aaazzze';
|
//UPDATE `projetphp` SET `security_level` = '6' WHERE `projetphp`.`login` = 'aaazzze';
|
||||||
if(isset($_POST["updatePW"], $_POST["datene"], $_POST["email"], $_POST["pw"], $_POST["sl"], $_POST["login"]))
|
if(isset($_POST["updatePW"], $_POST["datene"], $_POST["email"], $_POST["pw"], $_POST["sl"], $_POST["login"]))
|
||||||
if($_POST["updatePW"] == "true")
|
if(htmlspecialchars($_POST["updatePW"], ENT_QUOTES, 'UTF-8') == "true")
|
||||||
{
|
{
|
||||||
$req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `mot_de_passe` = :pw, `security_level` = :sl WHERE `projetphp`.`login` = :login');
|
$req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `mot_de_passe` = :pw, `security_level` = :sl WHERE `projetphp`.`login` = :login');
|
||||||
$req->execute(array(
|
$req->execute(array(
|
||||||
'datene' => $_POST["datene"],
|
'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'),
|
||||||
'email' => $_POST["email"],
|
'email' => htmlspecialchars($_POST["email"], ENT_QUOTES, 'UTF-8'),
|
||||||
'pw' => md5($_POST["pw"]),
|
'pw' => md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8')),
|
||||||
'sl' => $_POST["sl"],
|
'sl' => htmlspecialchars($_POST["sl"], ENT_QUOTES, 'UTF-8'),
|
||||||
'login' => $_POST["login"],
|
'login' => htmlspecialchars($_POST["login"], ENT_QUOTES, 'UTF-8'),
|
||||||
));
|
));
|
||||||
$ret["return"] = true;
|
$ret["return"] = true;
|
||||||
$ret["pw"] = md5($_POST["pw"]);
|
$ret["pw"] = md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8'));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `security_level` = :sl WHERE `projetphp`.`login` = :login');
|
$req = $bdd->prepare('UPDATE `projetphp` SET `date_naissance` = :datene, `e_mail` = :email, `security_level` = :sl WHERE `projetphp`.`login` = :login');
|
||||||
$req->execute(array(
|
$req->execute(array(
|
||||||
'datene' => $_POST["datene"],
|
'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'),
|
||||||
'email' => $_POST["email"],
|
'email' => htmlspecialchars($_POST["email"], ENT_QUOTES, 'UTF-8'),
|
||||||
'sl' => $_POST["sl"],
|
'sl' => htmlspecialchars($_POST["sl"], ENT_QUOTES, 'UTF-8'),
|
||||||
'login' => $_POST["login"],
|
'login' => htmlspecialchars($_POST["login"], ENT_QUOTES, 'UTF-8'),
|
||||||
));
|
));
|
||||||
$ret["return"] = true;
|
$ret["return"] = true;
|
||||||
$ret["pw"] = $_POST["pw"];
|
$ret["pw"] = htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
else;
|
else;
|
||||||
|
|
||||||
|
|
73
script.js
73
script.js
|
@ -1,11 +1,40 @@
|
||||||
$(function() {
|
$(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~~~~~~~~~~~~~~~~*/
|
/*~~~~~~~~~~~~~~~~TR TO EDIT~~~~~~~~~~~~~~~~*/
|
||||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||||
$("#allRecord").on("click", ".editUser", function() {
|
$("#allRecord").on("click", ".editUser", function() {
|
||||||
$(this).toggleClass('fa-edit fa-check');
|
$(this).toggleClass('fa-edit fa-check');
|
||||||
$(this).toggleClass('editUser confirmEditUser');
|
$(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]);
|
j= $($("td", $(this).parent().parent())[i]);
|
||||||
className = j.attr('class');
|
className = j.attr('class');
|
||||||
|
@ -26,6 +55,10 @@ $(function() {
|
||||||
else if (j.attr('class') == "datene")
|
else if (j.attr('class') == "datene")
|
||||||
inputOptions += 'type="date" '
|
inputOptions += 'type="date" '
|
||||||
j.html('<input '+inputOptions+' value="'+(j.attr('class')=="pw"?'':ltrim(j.html()))+'" />');
|
j.html('<input '+inputOptions+' value="'+(j.attr('class')=="pw"?'':ltrim(j.html()))+'" />');
|
||||||
|
if(className=="pw")
|
||||||
|
{
|
||||||
|
j.append("<div>le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9</div>")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -48,6 +81,8 @@ $(function() {
|
||||||
className = j.attr('class');
|
className = j.attr('class');
|
||||||
if(className == "pw" && data === true)
|
if(className == "pw" && data === true)
|
||||||
value = $('input,select', j).data("oldpw");
|
value = $('input,select', j).data("oldpw");
|
||||||
|
else if(className=="login")
|
||||||
|
value = ltrim(j.html());
|
||||||
else
|
else
|
||||||
value = $('input,select', j).val();
|
value = $('input,select', j).val();
|
||||||
dataToSend[className] = value;
|
dataToSend[className] = value;
|
||||||
|
@ -56,7 +91,7 @@ $(function() {
|
||||||
try {
|
try {
|
||||||
if(data.return == true)
|
if(data.return == true)
|
||||||
{
|
{
|
||||||
for(i=0; i<tds.length-1;i++) //On change les input en pure html
|
for(i=1; i<tds.length-1;i++) //On change les input en pure html
|
||||||
{
|
{
|
||||||
j= $(tds[i]);
|
j= $(tds[i]);
|
||||||
className = j.attr('class');
|
className = j.attr('class');
|
||||||
|
@ -64,7 +99,6 @@ $(function() {
|
||||||
value = data.pw;
|
value = data.pw;
|
||||||
else
|
else
|
||||||
value = $('input,select', j).val();
|
value = $('input,select', j).val();
|
||||||
dataToSend[className] = value;
|
|
||||||
j.html(value);
|
j.html(value);
|
||||||
}
|
}
|
||||||
swal("all done");
|
swal("all done");
|
||||||
|
@ -88,22 +122,25 @@ $(function() {
|
||||||
tds = $("td", $(this).parent().parent()); //Récupère les td concernant le click
|
tds = $("td", $(this).parent().parent()); //Récupère les td concernant le click
|
||||||
tr = $(this).parent().parent(); //Récupère le tr concernant le click
|
tr = $(this).parent().parent(); //Récupère le tr concernant le click
|
||||||
that = this;
|
that = this;
|
||||||
if ($(".pw input", tr).val() === "") {
|
if(mailPatern.test($(".email input", tr).val()) && (passwordPatern.test($(".pw input", tr).val()) || $(".pw input", tr).val() ==""))
|
||||||
callBackVerif(true);
|
if ($(".pw input", tr).val() === "") {
|
||||||
}
|
callBackVerif(true);
|
||||||
else {
|
}
|
||||||
swal({
|
else {
|
||||||
closeOnClickOutside: false,
|
swal({
|
||||||
closeOnEsc: false,
|
closeOnClickOutside: false,
|
||||||
content: {
|
closeOnEsc: false,
|
||||||
element: "input",
|
content: {
|
||||||
attributes: {
|
element: "input",
|
||||||
placeholder: "Confirmer le mot de passe",
|
attributes: {
|
||||||
type: "password",
|
placeholder: "Confirmer le mot de passe",
|
||||||
|
type: "password",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
}).then(callBackVerif);
|
||||||
}).then(callBackVerif);
|
}
|
||||||
}
|
else
|
||||||
|
swal( "Oops" , "Input don't respect rules !" , "error" );
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue