-
Notifications
You must be signed in to change notification settings - Fork 0
/
mot_passe_oublier.php
149 lines (105 loc) · 5.57 KB
/
mot_passe_oublier.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
session_start();
include('./includes/connect.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verification du compte</title>
<!-- google font -->
<link href='https://fonts.googleapis.com/css?family=Alice' rel='stylesheet'>
<!-- bootstrap-css -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- font awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- sweetalert2 -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js"></script>
<!-- css file -->
<link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">
</head>
<body>
<main class="login-form mt-5">
<div class="container mt-5">
<form name='w-50 m-auto mt-5' action="" method="post">
<input type="email" name="email" id="" class="form-control mb-3 w-50 m-auto" value='<?php if(isset($_SESSION['email_pour_password'])) echo $_SESSION['email_pour_password']; ?>' placeholder='Votre email'>
<input class='form-control btn-primary w-50 m-auto' name='envoyer_password_code' type="submit" value="Envoyer moi un code de verification">
</form>
</div>
</main>
<?php
if(isset($_POST["envoyer_password_code"])){
$email_utilisateur = htmlspecialchars($_POST['email']);
$select_utilisateur = $con->query("SELECT * FROM `utilisateurs` WHERE email_utilisateur like '$email_utilisateur'");
$rows = $select_utilisateur->rowCount();
while($ligne = $select_utilisateur->fetch(PDO::FETCH_OBJ)){
$nom_utilisateur = $ligne->nom_utilisateur;
}
if($rows == 0){
echo "<script>Swal.fire({position: 'center',
icon: 'error',
title: 'Pas de compte associe a cette email',
showConfirmButton: true});
</script>";
}
else{
$otp = rand(100000,999999);
$_SESSION['otp'] = $otp;
$_SESSION['mail'] = $email_utilisateur;
require "Mail/phpmailer/PHPMailerAutoload.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
// $mail->Username='[email protected]';
// $mail->Password='123abc$456ABC';
$mail->Username='[email protected]';
$mail->Password='tsue nioq ieim tkgc';
// $mail->setFrom('[email protected]', 'ElectroShop');
// $mail->addAddress($_POST["email"]);
$mail->setFrom('[email protected]', 'ElectroShop');
$mail->addAddress($_POST["email"]);
$mail->isHTML(true);
$mail->Subject="Votre Code de Verification Pour mettre à jour le mot de Passe";
$mail->Body="<p>M/Mme $nom_utilisateur, </p><br><br> <h3 style='font-size: 50px;'>Ce Code vous permet de récuperer votre mot de passe de votre compte sur <strong>ElectroShop</strong> :</h3><h1 style='color:red;margin:auto;font-size: 150px'>$otp</h1>
<br><br>
<p>Cordialement,</p>
<p><strong>Equipe ElectroShop</strong></p>
<p><strong>IRISI1</strong></p>
<p><strong>2021-2022</strong></p>
<p><strong>Fstg - Marrakech</strong></p>";
if(!$mail->send()){
echo "<script>Swal.fire({position: 'center',
icon: 'error',
title: 'Email n\'existe pas',
showConfirmButton: true});
</script>";
}else{
$modifier_utilisateur = "UPDATE utilisateurs SET verification_code=:verification_code WHERE email_utilisateur=:email_utilisateur";
$modifier= $con->prepare($modifier_utilisateur);
$modifier->execute(array('verification_code' => $otp,'email_utilisateur' => $email_utilisateur));
echo "<script>Swal.fire({position: 'center',
icon: 'success',
title: 'Un code à été envoyer à $email_utilisateur',
showConfirmButton: true}).then((result) => {
if (result.isConfirmed) {
Swal.fire(
window.open('./mot_passe_oublier_verification.php','_self')
)
}else{
window.open('./mot_passe_oublier_verification.php','_self')
}
});</script>";
}
//----Fin Envoyer Code Verification
}
}
?>
<!-- bootstrap-JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</body>
</html>