This commit is contained in:
adri 2019-01-02 10:43:38 +01:00
parent a5d08063d8
commit a345a22565
3 changed files with 252 additions and 271 deletions

View File

@ -9,6 +9,7 @@ $reponse = $bdd->query('SELECT * FROM projetphp');
?> ?>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -24,6 +25,7 @@ $reponse = $bdd->query('SELECT * FROM projetphp');
<link rel="stylesheet" href="style.css?<?php echo date('l jS \of F Y h:i:s A'); ?>"> <link rel="stylesheet" href="style.css?<?php echo date('l jS \of F Y h:i:s A'); ?>">
<script src="script.js?<?php echo date('l jS \of F Y h:i:s A'); ?>"></script> <script src="script.js?<?php echo date('l jS \of F Y h:i:s A'); ?>"></script>
</head> </head>
<body> <body>
<table id="allRecord"> <table id="allRecord">
<thead> <thead>
@ -38,20 +40,24 @@ $reponse = $bdd->query('SELECT * FROM projetphp');
</thead> </thead>
<tbody> <tbody>
<?php <?php
while($data = $reponse->fetch()) while ($data = $reponse->fetch()) {
{
?> ?>
<tr class="record"> <tr class="record">
<td class="login"> <td class="login">
<?= ($data["login"]) ?></td> <?= ($data["login"]) ?>
</td>
<td class="datene"> <td class="datene">
<?= ($data["date_naissance"]) ?></td> <?= ($data["date_naissance"]) ?>
</td>
<td class="email"> <td class="email">
<?= ($data["e_mail"]) ?></td> <?= ($data["e_mail"]) ?>
</td>
<td class="pw"> <td class="pw">
<?= ($data["mot_de_passe"]) ?></td> <?= ($data["mot_de_passe"]) ?>
</td>
<td class="sl"> <td class="sl">
<?= ($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
@ -63,4 +69,5 @@ $reponse = $bdd->query('SELECT * FROM projetphp');
</tbody> </tbody>
</table> </table>
</body> </body>
</html> </html>

View File

@ -9,18 +9,16 @@ try {
} }
//DELETE FROM `projetphp` WHERE `projetphp`.`login` = \'caprout\' //DELETE FROM `projetphp` WHERE `projetphp`.`login` = \'caprout\'
if(isset($_POST["userToDel"])) if (isset($_POST["userToDel"])) {
{
$req = $bdd->prepare('DELETE FROM `projetphp` WHERE `projetphp`.`login`=:login'); $req = $bdd->prepare('DELETE FROM `projetphp` WHERE `projetphp`.`login`=:login');
$req->execute(array( 'login' => htmlspecialchars($_POST["userToDel"]))); $req->execute(array( 'login' => htmlspecialchars($_POST["userToDel"])));
} }
//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(preg_match('/^(([^<>()\[\]\\.,;:\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,}))$/', $_POST["email"])) if (preg_match('/^(([^<>()\[\]\\.,;:\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,}))$/', $_POST["email"])) {
if(htmlspecialchars($_POST["updatePW"], ENT_QUOTES, 'UTF-8') == "true" && preg_match('/^[a-z]{8,16}$/',$_POST["pw"])) if (htmlspecialchars($_POST["updatePW"], ENT_QUOTES, 'UTF-8') == "true" && preg_match('/^[a-z]{8,16}$/', $_POST["pw"])) {
{
$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' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'), 'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'),
@ -31,9 +29,7 @@ if(isset($_POST["updatePW"], $_POST["datene"], $_POST["email"], $_POST["pw"], $_
)); ));
$ret["return"] = true; $ret["return"] = true;
$ret["pw"] = md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8')); $ret["pw"] = md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8'));
} } elseif (htmlspecialchars($_POST["updatePW"], ENT_QUOTES, 'UTF-8') == "false") {
else if(htmlspecialchars($_POST["updatePW"], ENT_QUOTES, 'UTF-8') == "false")
{
$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' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'), 'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'),
@ -43,9 +39,8 @@ if(isset($_POST["updatePW"], $_POST["datene"], $_POST["email"], $_POST["pw"], $_
)); ));
$ret["return"] = true; $ret["return"] = true;
$ret["pw"] = htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8'); $ret["pw"] = htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8');
} else ;
} else ;
} }
else;
else;
echo json_encode((object)$ret); echo json_encode((object)$ret);
?>

View File

@ -22,25 +22,19 @@ mailPatern=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0
$(function() { $(function() {
$("#allRecord").on("keyup", ".pw input", function() { $("#allRecord").on("keyup", ".pw input", function() {
if(passwordPatern.test($(this).val()) || $(this).val() == "") if (passwordPatern.test($(this).val()) || $(this).val() == "") {
{
$(this).css("background-color", ""); $(this).css("background-color", "");
$('div', $(this).parent()).css("display", "none"); $('div', $(this).parent()).css("display", "none");
} } else {
else
{
$(this).css("background-color", "red"); $(this).css("background-color", "red");
$('div', $(this).parent()).css("display", "block"); $('div', $(this).parent()).css("display", "block");
} }
}); });
$("#allRecord").on("keyup", ".email input", function() { $("#allRecord").on("keyup", ".email input", function() {
if(mailPatern.test($(this).val())) if (mailPatern.test($(this).val())) {
{
$(this).css("background-color", ""); $(this).css("background-color", "");
$('div', $(this).parent()).css("display", "none"); $('div', $(this).parent()).css("display", "none");
} } else {
else
{
$(this).css("background-color", "red"); $(this).css("background-color", "red");
$('div', $(this).parent()).css("display", "block"); $('div', $(this).parent()).css("display", "block");
} }
@ -53,30 +47,22 @@ $("#allRecord").on("click", ".delUser", function() {
tr = $(this).parent().parent(); tr = $(this).parent().parent();
var login = ""; var login = "";
var sl = ""; var sl = "";
if(tr.find("i.editUser").length !== 0) if (tr.find("i.editUser").length !== 0) {
{
sl = ltrim($('.sl', tr).html()) sl = ltrim($('.sl', tr).html())
login = $('.login', tr).html(); login = $('.login', tr).html();
} } else if (tr.find("i.confirmEditUser").length !== 0) {
else if(tr.find("i.confirmEditUser").length !== 0)
{
sl = $('.sl select', tr).val(); sl = $('.sl select', tr).val();
login = $('.login', tr).html(); login = $('.login', tr).html();
} } else {
else
{
try { try {
login = "New user " + $('.login input', tr).val(); login = "New user " + $('.login input', tr).val();
newUser = true; newUser = true;
} } catch (e) {
catch(e)
{
swal("error : " + e); swal("error : " + e);
return; return;
} }
} }
if(sl == "10") if (sl == "10") {
{
swal("Oops", "You can't del user with sl 10", "error"); swal("Oops", "You can't del user with sl 10", "error");
return; return;
} }
@ -91,7 +77,9 @@ $("#allRecord").on("click", ".delUser", function() {
.then((willDelete) => { .then((willDelete) => {
if (willDelete) { if (willDelete) {
if (!newUser) if (!newUser)
$.post("post.php", {userToDel: login}, function(){ $.post("post.php", {
userToDel: login
}, function() {
tr.remove(); tr.remove();
swal("Poof! " + login + " has been deleted!", { swal("Poof! " + login + " has been deleted!", {
icon: "success", icon: "success",
@ -116,29 +104,24 @@ $("#allRecord").on("click", ".delUser", function() {
$("#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=1; 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');
if(className == "sl") if (className == "sl") {
{
val = ltrim(j.html()); val = ltrim(j.html());
j.html('<select>\ j.html('<select>\
<option value="1" ' + (val == "1" ? 'selected' : '') + '>1</option>\ <option value="1" ' + (val == "1" ? 'selected' : '') + '>1</option>\
<option value="5" ' + (val == "5" ? 'selected' : '') + '>5</option>\ <option value="5" ' + (val == "5" ? 'selected' : '') + '>5</option>\
<option value="10" ' + (val == "10" ? 'selected' : '') + '>10</option>\ <option value="10" ' + (val == "10" ? 'selected' : '') + '>10</option>\
</select>') </select>')
} } else {
else
{
inputOptions = ''; inputOptions = '';
if (className == "pw") if (className == "pw")
inputOptions += 'type="password" data-oldpw="' + ltrim(j.html()) + '" '; inputOptions += 'type="password" data-oldpw="' + ltrim(j.html()) + '" ';
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") 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>") j.append("<div>le mot de passe comporte entre 8 et 16 caractères parmi a..z A..Z 0..9</div>")
} }
} }
@ -171,8 +154,7 @@ $("#allRecord").on("click", ".delUser", function() {
} }
$.post("post.php", dataToSend, function(data) { $.post("post.php", dataToSend, function(data) {
try { try {
if(data.return == true) if (data.return == true) {
{
for (i = 1; 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]);
@ -186,16 +168,14 @@ $("#allRecord").on("click", ".delUser", function() {
swal("all done"); swal("all done");
$(that).toggleClass('fa-check fa-edit'); $(that).toggleClass('fa-check fa-edit');
$(that).toggleClass('confirmEditUser editUser'); $(that).toggleClass('confirmEditUser editUser');
} } else
else
swal(data); swal(data);
} catch (e) { } catch (e) {
swal("Oops", "Something went wrong!<br>" + e, "error"); swal("Oops", "Something went wrong!<br>" + e, "error");
} }
console.log(data.return) console.log(data.return)
}, "json"); }, "json");
} } else {
else {
swal("Oops", "Password don't match !", "error"); swal("Oops", "Password don't match !", "error");
} }
} }
@ -220,8 +200,7 @@ $("#allRecord").on("click", ".delUser", function() {
}, },
}, },
}).then(callBackVerif); }).then(callBackVerif);
} } else
else
swal("Oops", "Input don't respect rules !", "error"); swal("Oops", "Input don't respect rules !", "error");
}); });
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/