projetphp/post.php

93 lines
4.2 KiB
PHP
Raw Normal View History

2018-12-30 17:41:15 +01:00
<?php
2019-01-02 13:23:07 +01:00
require_once("function.php");
$emailPatern = '/^(([^<>()\[\]\\.,;:\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,}))$/';
$pwPatern = '/^[a-z]{8,16}$/';
$loginPatern = '/^[a-z]{8,16}$/';
2018-12-30 17:41:15 +01:00
$ret["return"] = false;
$ret["pw"] = null;
try {
2019-01-02 10:43:38 +01:00
$config = include('config.php');
$bdd = new PDO('mysql:host='.$config['host'].';dbname='.$config['dbName'].';charset=utf8', $config['username'], $config['pw']);
2018-12-30 17:41:15 +01:00
} catch (Exception $e) {
2019-01-02 10:43:38 +01:00
die('Erreur : '.$e->getMessage());
2018-12-30 17:41:15 +01:00
}
2018-12-30 21:26:55 +01:00
//DELETE FROM `projetphp` WHERE `projetphp`.`login` = \'caprout\'
2019-01-02 10:43:38 +01:00
if (isset($_POST["userToDel"])) {
$req = $bdd->prepare('DELETE FROM `projetphp` WHERE `projetphp`.`login`=:login');
$req->execute(array( 'login' => htmlspecialchars($_POST["userToDel"])));
2019-01-02 13:23:07 +01:00
$req->closeCursor();
2018-12-30 21:26:55 +01:00
}
2019-01-02 13:23:07 +01:00
elseif (isset($_POST["userExist"])) {
if(userExist($_POST["userExist"]))
{
$ret["return"] = "userExist";
}
else
{
$ret["return"] = "userNotExist";
}
}
//INSERT INTO `projetphp` (`login`, `date_naissance`, `e_mail`, `mot_de_passe`, `security_level`) VALUES ('blipblop', '2019-01-09', 'aaaaa@aaa.cc', MD5('sdfqsdfsfd'), '5');
elseif (isset($_POST["newUser"],$_POST["datene"], $_POST["email"], $_POST["pw"], $_POST["sl"]) && $_POST["newUser"] == "true") {
if(preg_match($loginPatern, $_POST["login"]) && preg_match($emailPatern, $_POST[email]) && preg_match($pwPatern, $_POST["pw"]))
{
if(userExist($_POST["login"]))
{
$ret["return"] = "userExist";
}
else
{
$ret["pw"] = md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8'));
$req = $bdd->prepare('INSERT INTO `projetphp` (`login`, `date_naissance`, `e_mail`, `mot_de_passe`, `security_level`) VALUES (:login, :datene, :email, :pw, :slvl)');
$req->execute(array(
'login' => htmlspecialchars($_POST["login"], ENT_QUOTES, 'UTF-8'),
'datene' => htmlspecialchars($_POST["datene"], ENT_QUOTES, 'UTF-8'),
'email' => (htmlspecialchars($_POST["email"], ENT_QUOTES, 'UTF-8')),
'pw' => $ret["pw"],
'slvl' => htmlspecialchars($_POST["slvl"], ENT_QUOTES, 'UTF-8'),
));
$req->closeCursor();
$ret["return"] = true;
}
}
else
{
$ret["return"] = "patern mismatch !".preg_match($loginPatern, $_POST["login"]) ."_". preg_match($emailPatern, $_POST[email]) ."_". preg_match($pwPatern, $_POST["pw"]);
}
}
2018-12-30 21:26:55 +01:00
2018-12-30 17:41:15 +01:00
//UPDATE `projetphp` SET `security_level` = '6' WHERE `projetphp`.`login` = 'aaazzze';
2019-01-02 13:23:07 +01:00
else if (isset($_POST["newUser"], $_POST["updatePW"], $_POST["datene"], $_POST["email"], $_POST["pw"], $_POST["sl"], $_POST["login"]) && $_POST["newUser"] == "false") {
if (preg_match($emailPatern, $_POST["email"])) {
if (htmlspecialchars($_POST["updatePW"], ENT_QUOTES, 'UTF-8') == "true" && preg_match($pwPatern, $_POST["pw"])) {
2019-01-02 10:43:38 +01:00
$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(
'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'),
));
2019-01-02 13:23:07 +01:00
$req->closeCursor();
2019-01-02 10:43:38 +01:00
$ret["return"] = true;
$ret["pw"] = md5(htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8'));
} elseif (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->execute(array(
'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'),
));
2019-01-02 13:23:07 +01:00
$req->closeCursor();
2019-01-02 10:43:38 +01:00
$ret["return"] = true;
$ret["pw"] = htmlspecialchars($_POST["pw"], ENT_QUOTES, 'UTF-8');
} else ;
} else ;
}
2018-12-30 17:41:15 +01:00
echo json_encode((object)$ret);