Repository navigation
Expand file tree
/
Copy pathverifyEmail.php
More file actions
74 lines (68 loc) · 2.95 KB
/
Copy pathverifyEmail.php
File metadata and controls
74 lines (68 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
session_start();
require "conf.inc.php";
require "functions.php";
if (isset($_POST["inputEmail"])) {
if (count($_POST) == 1
&& !empty($_POST["inputEmail"])) {
$error = false;
$listOfErrors = [];
$success = false;
$listOfSuccess = [];
$email = strtolower(trim($_POST["inputEmail"]));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = true;
$listOfErrors[] = "L'email n'est pas valide";
}
if (!$error) {
$pdo = connectDB();
$queryPrepared = $pdo->prepare("SELECT idUser FROM USER WHERE emailAddress = :email");
$queryPrepared->execute([":email" => $email]);
$result = $queryPrepared->fetch();
$id = $result["idUser"];
if (empty($result)) {
$error = true;
$listOfErrors[] = "Aucun compte trouvé";
} else {
$success = true;
$listOfSuccess[] = "Un email vous a été envoyé pour réinitialiser votre mot de passe";
$token = createToken($email);
$queryPrepared = $pdo->prepare("UPDATE USER, USERTOKEN SET USERTOKEN.token = :token WHERE emailAddress = :email
AND idUser = :id
AND idUser = user
AND tokenType = 'Site'");
$queryPrepared->execute([
":token" => $token,
":email" => $email,
":id" => $id
]);
$admin = ($_SERVER["SERVER_ADMIN"]);
$destination = $email;
$domaineAddresse = substr($admin, strpos($admin, '@') + 1, strlen($admin));
$header = "From: no-reply@" . $domaineAddresse . "\n";
$header .= "X-Sender: <no-reply@" . $domaineAddresse . "\n";
$header .= "X-Mailer: PHP\n";
$header .= "Return-Path: <no-reply@" . $domaineAddresse . "\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\n";
$subject = "Réinitialisation de votre mot de passe";
$link = "https://" . $admin . "/newPassword.php?id=" . $id . "&cle=" . $token;
$html = file_get_contents("./mail.php");
$html = str_replace("{{LINK}}", $link, $html);
mail($destination, $subject, $html, $header);
}
if (!$error) {
unset($_POST["inputEmail"]);
$_SESSION["success"] = $listOfSuccess;
header("Location: forgotPassword.php");
} else {
unset($_POST["inputEmail"]);
$_SESSION["errors"] = $listOfErrors;
header("Location: forgotPassword.php");
}
}
} else {
die("Tentative de Hack .... !!!!");
}
} else {
header("Location: login.php");
}