191 lines
7.3 KiB
PHP
191 lines
7.3 KiB
PHP
<?php
|
|
// Mulai session
|
|
session_start();
|
|
|
|
// Include file config dan library PHPMailer
|
|
include '../config.php';
|
|
require '../vendor/autoload.php';
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Lupa Password</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
|
|
<!-- Fonts -->
|
|
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700&display=swap" rel="stylesheet">
|
|
|
|
<!-- Font Awesome -->
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
|
|
|
<!-- Custom CSS -->
|
|
<style>
|
|
body {
|
|
background: #FFFAE6;
|
|
font-family: 'Lato', sans-serif;
|
|
}
|
|
.login-wrap {
|
|
background: #FFD28F;
|
|
padding: 30px;
|
|
border-radius: 10px;
|
|
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.form-control {
|
|
border: 2px solid #E6732A;
|
|
background: #FFF5E1;
|
|
color: #2F2F2F;
|
|
}
|
|
.form-control::placeholder {
|
|
color: #A65F23;
|
|
}
|
|
.btn-primary {
|
|
background-color: #FFA836 !important;
|
|
border-color: #E6732A !important;
|
|
color: white !important;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: #E6732A !important;
|
|
border-color: #C15A1A !important;
|
|
}
|
|
.text-center a {
|
|
color: #E6732A;
|
|
}
|
|
.text-center a:hover {
|
|
color: #C15A1A;
|
|
}
|
|
.icon {
|
|
background: #E6732A;
|
|
color: white;
|
|
padding: 15px;
|
|
border-radius: 50%;
|
|
font-size: 24px;
|
|
width: 50px;
|
|
height: 50px;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
margin: auto;
|
|
}
|
|
</style>
|
|
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="css/style.css">
|
|
|
|
<!-- SweetAlert2 -->
|
|
<script src="../dist/sweetalert2.all.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<section class="ftco-section">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 text-center mb-5">
|
|
<h2 class="heading-section">Lupa Password</h2>
|
|
</div>
|
|
</div>
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 col-lg-5">
|
|
<div class="login-wrap p-4 p-md-5">
|
|
<div class="icon d-flex align-items-center justify-content-center">
|
|
<span class="fa fa-envelope-o"></span>
|
|
</div>
|
|
<h3 class="text-center mb-4">Masukkan Email Anda</h3>
|
|
|
|
<!-- Form Lupa Password -->
|
|
<form action="" method="POST" class="login-form">
|
|
<div class="form-group">
|
|
<input type="email" name="email" class="form-control rounded-left" placeholder="Email" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary rounded submit p-3 px-5" name="submit">Kirim Email</button>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- PHP Script -->
|
|
<?php
|
|
if (isset($_POST['submit'])) {
|
|
$email = mysqli_real_escape_string($conn, $_POST['email']);
|
|
|
|
// Cek apakah email terdaftar
|
|
$cek_email = mysqli_query($conn, "SELECT * FROM admin WHERE email = '$email'");
|
|
|
|
if (mysqli_num_rows($cek_email) > 0) {
|
|
$token = bin2hex(random_bytes(32));
|
|
$reset_link = "http://localhost/admin-login/reset_password.php?token=$token";
|
|
|
|
// Simpan token ke database
|
|
$query = "UPDATE admin SET reset_token = '$token', token_expiry = DATE_ADD(NOW(), INTERVAL 1 HOUR) WHERE email = '$email'";
|
|
mysqli_query($conn, $query);
|
|
|
|
$mail = new PHPMailer(true);
|
|
try {
|
|
// Konfigurasi Gmail SMTP
|
|
$mail->isSMTP();
|
|
$mail->Host = 'smtp.gmail.com';
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = 'chickycuts2025@gmail.com'; // Email pengirim (Gmail kamu)
|
|
$mail->Password = 'etccszhnwgvvgxfx'; // App Password tanpa spasi
|
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
|
$mail->Port = 587;
|
|
|
|
// Konfigurasi email
|
|
$mail->setFrom('chickycuts2025@gmail.com', 'ChickyCuts');
|
|
$mail->addAddress($email); // Email penerima dari form input
|
|
$mail->Subject = 'Reset Password Anda';
|
|
$mail->isHTML(true);
|
|
$mail->Body = "
|
|
<p>Halo,</p>
|
|
<p>Silakan klik link berikut untuk mereset password Anda:</p>
|
|
<a href='$reset_link'>$reset_link</a>
|
|
<p>Link ini hanya berlaku selama 1 jam.</p>
|
|
";
|
|
|
|
$mail->send();
|
|
|
|
echo "<script>
|
|
Swal.fire({
|
|
title: 'Email Terkirim!',
|
|
text: 'Silakan cek email Anda untuk mereset password.',
|
|
icon: 'success'
|
|
}).then(() => {
|
|
window.location = '';
|
|
});
|
|
</script>";
|
|
} catch (Exception $e) {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Oops...',
|
|
text: 'Gagal mengirim email. Error: {$mail->ErrorInfo}',
|
|
});
|
|
</script>";
|
|
}
|
|
} else {
|
|
echo "<script>
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Email Tidak Ditemukan',
|
|
text: 'Email yang Anda masukkan tidak terdaftar.',
|
|
});
|
|
</script>";
|
|
}
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Scripts -->
|
|
<script src="js/jquery.min.js"></script>
|
|
<script src="js/popper.js"></script>
|
|
<script src="js/bootstrap.min.js"></script>
|
|
<script src="js/main.js"></script>
|
|
</body>
|
|
</html>
|