Activation de compte terminée
This commit is contained in:
parent
d0c24624aa
commit
8664630961
4 changed files with 208 additions and 27 deletions
|
|
@ -491,3 +491,38 @@ function createValidationCode($bdd, $user, $ttlMinutes = 60)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
function updateUserPassword($bdd, $user, $hashPassword)
|
||||
{
|
||||
$stmt = mysqli_prepare(
|
||||
$bdd,
|
||||
"UPDATE utilisateurs SET password = ? WHERE username = ?"
|
||||
);
|
||||
|
||||
mysqli_stmt_bind_param($stmt, "ss", $hashPassword, $user);
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
$success = mysqli_stmt_affected_rows($stmt) >= 0;
|
||||
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
function getUserFromCode($bdd, $code)
|
||||
{
|
||||
$stmt = mysqli_prepare(
|
||||
$bdd,
|
||||
"SELECT utilisateur FROM codes WHERE code = ? LIMIT 1"
|
||||
);
|
||||
|
||||
mysqli_stmt_bind_param($stmt, "s", $code);
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
return $row ? $row['utilisateur'] : null;
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ $message = ["
|
|||
<h1>Validation de création de compte</h1>
|
||||
<p>L'utilisateur {user} a demandé la création de son compte.</p>
|
||||
Le mail de validation sera envoyé à l'adresse : {mail}<br>
|
||||
Si vous voulez accepter, cliquez <a href='http://172.17.0.224/validate.php?user={user}&email={email}'>ici</a><br>
|
||||
Si vous voulez accepter, cliquez <a href='http://172.17.0.54/intranetv2/validate.php?user={user}&email={email}'>ici</a><br>
|
||||
<p>Sinon, vous pouvez simplement ignorer ce message</p><br>
|
||||
<p>Des bisous</p>
|
||||
","
|
||||
|
|
@ -36,17 +36,17 @@ if(isset($_GET['type'])){
|
|||
|
||||
if($type == 0){
|
||||
$user = $_GET['user'];
|
||||
$email = $_GET['email'];
|
||||
$email = urldecode($_GET['email']);
|
||||
$sendto = "blemaire@apeimbge.fr";
|
||||
$message[0] = str_replace("{user}", $user, $message[0]);
|
||||
$message[0] = str_replace('{mail}', $email, $message[0]);
|
||||
$message[0] = str_replace('{email}', $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]);
|
||||
$message[1] = str_replace("{lien}", "http://172.17.0.54/intranetv2/createPassword.php?code=" . $validationCode["code"], $message[1]);
|
||||
$message[1] = str_replace("{user}", $user, $message[1]);
|
||||
$message[1] = str_replace("{email}", $email, $message[1]);
|
||||
}
|
||||
|
|
|
|||
91
activate.php
91
activate.php
|
|
@ -1,24 +1,95 @@
|
|||
<?php
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
header('location: ./Assets/sendMail.php?type=0&user=' . $_POST['user'] . '&email=' . htmlspecialchars($_POST['mail']));
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>Activer mon compte</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.note {
|
||||
font-size: 0.9rem;
|
||||
color: #6c757d;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Activer mon compte sur l'intranet</h1>
|
||||
<form action="" method="post">
|
||||
<label for="user">Veuillez entrer le nom d'utilisateur (APEIXXXX)</label>
|
||||
<input type="text" name="user" id="user" placeholder="APEIXXXX" required><br>
|
||||
<label for="mail">Veuillez entrer votre adresse mail (pcharlot@apeimbge.fr)</label>
|
||||
<input type="text" name="mail" id="mail" placeholder="pcharlot@apeimbge.fr" required><br>
|
||||
<button type="submit">Demander l'activation</button>
|
||||
|
||||
<body class="d-flex align-items-center justify-content-center vh-100">
|
||||
|
||||
<div class="container" style="max-width:500px;">
|
||||
|
||||
<div class="card p-4">
|
||||
|
||||
<h1 class="h4 text-center mb-4 title">
|
||||
Activer mon compte sur l'intranet
|
||||
</h1>
|
||||
|
||||
<form method="post">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="user" class="form-label">
|
||||
Nom d'utilisateur
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="user"
|
||||
id="user"
|
||||
placeholder="APEIXXXX"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="mail" class="form-label">
|
||||
Adresse mail
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
class="form-control"
|
||||
name="mail"
|
||||
id="mail"
|
||||
placeholder="pcharlot@apeimbge.fr"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Demander l'activation
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<h3>Veuillez ne pas faire la demande plusieurs fois.</h3>
|
||||
|
||||
<p class="text-center mt-3 note">
|
||||
Veuillez ne pas faire la demande plusieurs fois.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,20 +1,95 @@
|
|||
<?php
|
||||
include("./Assets/functions.php");
|
||||
$config = json_decode(file_get_contents("./Assets/config.json"), true);
|
||||
$bdd = connectBDD("localhost", $config["BDD_USER"], $config["BDD_PASSWD"], $config["BDD_NAME"]);
|
||||
|
||||
if (isset($_POST['password1'])) {
|
||||
if ($_POST['password1'] == $_POST['password2']) {
|
||||
$user = getUserFromCode($bdd, $_POST['code']);
|
||||
updateUserPassword($bdd, $user, hash('sha256', $_POST['password1']));
|
||||
header('location: index.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Activer mon compte</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>Créer mon mot de passe</title>
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
body {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Activer mon compte sur l'intranet</h1>
|
||||
<form action="" method="post">
|
||||
<label for="password1">Entrez votre nouveau mot de passe</label>
|
||||
<input type="password" name="password1" id="password1" required><br>
|
||||
<label for="password2">Confirmez votre mot de passe</label>
|
||||
<input type="password" name="password2" id="password2" required><br>
|
||||
<button type="submit">Créer mon mot de passe</button>
|
||||
|
||||
<body class="d-flex align-items-center justify-content-center vh-100">
|
||||
|
||||
<div class="container" style="max-width:500px;">
|
||||
|
||||
<div class="card p-4">
|
||||
|
||||
<h1 class="h4 text-center mb-4 title">
|
||||
Créer mon mot de passe
|
||||
</h1>
|
||||
|
||||
<form method="post">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="password1" class="form-label">
|
||||
Nouveau mot de passe
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
name="password1"
|
||||
id="password1"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="password2" class="form-label">
|
||||
Confirmer le mot de passe
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
class="form-control"
|
||||
name="password2"
|
||||
id="password2"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="code" value="<?= htmlspecialchars($_GET['code']) ?>">
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Créer mon mot de passe
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in a new issue