diff --git a/Assets/functions.php b/Assets/functions.php index da955f8..09e89ad 100644 --- a/Assets/functions.php +++ b/Assets/functions.php @@ -440,3 +440,54 @@ function getEventDate($bdd, $event) return $row ? $row['date'] : null; } + +function createValidationCode($bdd, $user, $ttlMinutes = 60) +{ + $table = "codes"; + $colCode = "code"; + $colUser = "utilisateur"; + $colExpire = "peremption"; + + $code = ""; + $exists = true; + + while ($exists) { + $code = bin2hex(random_bytes(16)); + + $checkStmt = mysqli_prepare($bdd, "SELECT id FROM `$table` WHERE `$colCode` = ? LIMIT 1"); + if ($checkStmt) { + mysqli_stmt_bind_param($checkStmt, "s", $code); + mysqli_stmt_execute($checkStmt); + mysqli_stmt_store_result($checkStmt); + + if (mysqli_stmt_num_rows($checkStmt) == 0) { + $exists = false; + } + mysqli_stmt_close($checkStmt); + } else { + return false; + } + } + + $expiresAt = date('Y-m-d H:i:s', time() + ($ttlMinutes * 60)); + + $insertSql = "INSERT INTO `$table` (`$colCode`, `$colUser`, `$colExpire`) VALUES (?, ?, ?)"; + $insertStmt = mysqli_prepare($bdd, $insertSql); + + if ($insertStmt) { + mysqli_stmt_bind_param($insertStmt, "sss", $code, $user, $expiresAt); + $success = mysqli_stmt_execute($insertStmt); + $insertId = mysqli_insert_id($bdd); + mysqli_stmt_close($insertStmt); + + if ($success) { + return [ + 'id' => $insertId, + 'code' => $code, + 'expire' => $expiresAt + ]; + } + } + + return false; +} \ No newline at end of file diff --git a/Assets/sendMail.php b/Assets/sendMail.php index 29c85ce..a6c6621 100644 --- a/Assets/sendMail.php +++ b/Assets/sendMail.php @@ -12,7 +12,7 @@ $message = ["

Validation de création de compte

L'utilisateur {user} a demandé la création de son compte.

Le mail de validation sera envoyé à l'adresse : {mail}
-Si vous voulez accepter, cliquez ici
+Si vous voulez accepter, cliquez ici

Sinon, vous pouvez simplement ignorer ce message


Des bisous

"," @@ -23,6 +23,11 @@ Merci de ne pas répondre à cet email.

{lien} "]; + +include('./functions.php'); +$config = json_decode(file_get_contents("./config.json"), true); +$bdd = connectBDD("localhost", $config["BDD_USER"], $config["BDD_PASSWD"], $config["BDD_NAME"]); + if(isset($_GET['type'])){ $type = $_GET['type']; }else{ @@ -32,8 +37,16 @@ if(isset($_GET['type'])){ if($type == 0){ $user = $_GET['user']; $email = $_GET['email']; + $sendto = "blemaire@apeimbge.fr"; $message[0] = str_replace("{user}", $user, $message[0]); $message[0] = str_replace('{mail}', $email, $message[0]); +}else{ + $user = $_GET['user']; + $email = $_GET['email']; + $sendto = $email; + $validationCode = createValidationCode($bdd, $user, 10080); + + $message[1] = str_replace("{lien}", "http://172.17.0.224/validate.php?code=" . $validationCode["code"], $message[1]); } $mail = new PHPMailer(true); @@ -52,7 +65,7 @@ try { $mail->isHTML(true); $mail->setFrom('intranet-apei@apeimbge.fr', 'Demande de connexion'); - //$mail->addAddress('blemaire@apeimbge.fr'); + $mail->addAddress($sendto); $mail->addAddress('erwann.philippe2@gmail.com'); $mail->Subject = $objet[$type]; diff --git a/activate.php b/activate.php index e60a5eb..ed8c6df 100644 --- a/activate.php +++ b/activate.php @@ -13,7 +13,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Activer mon compte sur l'intranet

- +

diff --git a/createPassword.php b/createPassword.php new file mode 100644 index 0000000..30817b9 --- /dev/null +++ b/createPassword.php @@ -0,0 +1,20 @@ + + + + + + + Activer mon compte + + +

Activer mon compte sur l'intranet

+ + +
+ +
+ +
+ + \ No newline at end of file diff --git a/validate.php b/validate.php new file mode 100644 index 0000000..da6861d --- /dev/null +++ b/validate.php @@ -0,0 +1,20 @@ + + + + + + + Validation de compte + + +

Validation de compte sur l'intranet

+

Le mail de validation va être envoyé à l'utilisateur.

+ + \ No newline at end of file