Code restructure push
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
require_once($rootPath . '/src/config/env.php');
|
||||
require_once($rootPath . '/src/config/session.php');
|
||||
require_once($rootPath . '/src/config/connection.php');
|
||||
require_once($rootPath . '/src/config/functions.php');
|
||||
|
||||
$response = array('status' => 'error', 'message' => 'Something went wrong');
|
||||
|
||||
// Check if the user is logged in
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
$response['message'] = 'You are not logged in.';
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
|
||||
// Check if form data is submitted
|
||||
if (isset($_POST['current_password'], $_POST['new_password'], $_POST['confirm_password'])) {
|
||||
$current_password = $_POST['current_password'];
|
||||
$new_password = $_POST['new_password'];
|
||||
$confirm_password = $_POST['confirm_password'];
|
||||
|
||||
// Validate new passwords
|
||||
if ($new_password !== $confirm_password) {
|
||||
$response['message'] = 'New passwords do not match.';
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch the stored hashed password from the database
|
||||
$sql = "SELECT password FROM users WHERE user_id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("i", $user_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$user = $result->fetch_assoc();
|
||||
|
||||
if (!$user) {
|
||||
$response['message'] = 'User not found.';
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Verify the current password
|
||||
if (!password_verify($current_password, $user['password'])) {
|
||||
$response['message'] = 'Current password is incorrect.';
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Hash the new password
|
||||
$new_password_hash = password_hash($new_password, PASSWORD_BCRYPT);
|
||||
|
||||
// Update the new password in the database
|
||||
$sql = "UPDATE users SET password = ? WHERE user_id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("si", $new_password_hash, $user_id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response['status'] = 'success';
|
||||
$response['message'] = 'Password changed successfully.';
|
||||
} else {
|
||||
$response['message'] = 'Failed to change password.';
|
||||
}
|
||||
} else {
|
||||
$response['message'] = 'Invalid form submission.';
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
?>
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
$headerStyle = 'light';
|
||||
include_once(dirname(dirname(dirname(__DIR__))) . '/header.php') ?>
|
||||
<style>
|
||||
@media (min-width: 991px) {
|
||||
.container {
|
||||
max-width: 720px;
|
||||
padding: 0 15px; /* Ensure padding doesn't cause overflow */
|
||||
}
|
||||
</style>
|
||||
<!-- Contact Form Area start -->
|
||||
<section class="contact-form-area py-120 rel z-1">
|
||||
<div class="container">
|
||||
<div class="row align-items-center">
|
||||
<!-- <div class="col-lg-6">
|
||||
<div style="text-align: center;">
|
||||
<img style="width:400px;" src="assets/images/logos/weblogo.png" alt="About">
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="">
|
||||
<div class="comment-form bgc-lighter z-1 rel mb-30 rmb-55">
|
||||
<form id="loginForm" class="loginForm" name="loginForm" method="post" data-aos="fade-left" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="section-title">
|
||||
<h2>Forgot your password?</h2>
|
||||
<div class="pt-20" style="text-align: center;" id="responseMessage"></div> <!-- Message display area -->
|
||||
</div>
|
||||
<div class="row mt-35">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="email">Email Address</label>
|
||||
<input type="email" id="email" name="email" class="form-control" placeholder="Enter Email" value="" required data-error="Please enter a valid Email address">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="csrf_token" value="<?php echo generateCSRFToken(); ?>">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group mb-0">
|
||||
<button type="submit" class="theme-btn style-two" style="width:100%;">Send Link</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Contact Form Area end -->
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#loginForm').on('submit', function(event) {
|
||||
event.preventDefault(); // Prevent the default form submission
|
||||
|
||||
$.ajax({
|
||||
url: 'send_reset_link',
|
||||
type: 'POST',
|
||||
data: $(this).serialize(),
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
// Parse response if needed
|
||||
if (typeof response === "string") {
|
||||
response = JSON.parse(response);
|
||||
}
|
||||
|
||||
if (response.status === 'success') {
|
||||
|
||||
$('#responseMessage').html('<div class="alert alert-success">' + response.message + '</div>');
|
||||
} else {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">Error sending link. Please contact support.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include_once(dirname(dirname(dirname(__DIR__))) . '/components/insta_footer.php'); ?>
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
$headerStyle = 'light';
|
||||
// Determine the correct path to header.php based on file location
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
include_once($rootPath . '/header.php');
|
||||
// Include Google login PHP logic
|
||||
require_once $rootPath . '/google-client/vendor/autoload.php';
|
||||
|
||||
$client = new Google_Client();
|
||||
$client->setClientId('948441222188-8qhboq2urr8o9n35mc70s5h2nhd52v0m.apps.googleusercontent.com');
|
||||
$client->setClientSecret('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');
|
||||
$client->setRedirectUri($_ENV['HOST'] . '/validate_login.php');
|
||||
$client->addScope("email");
|
||||
$client->addScope("profile");
|
||||
|
||||
// 👇 Add this to force the account picker
|
||||
$client->setPrompt('select_account');
|
||||
|
||||
$login_url = $client->createAuthUrl();
|
||||
?>
|
||||
|
||||
<style>
|
||||
@media (min-width: 991px) {
|
||||
.container {
|
||||
max-width: 720px;
|
||||
padding: 0 15px; /* Ensure padding doesn't cause overflow */
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<!-- Contact Form Area start -->
|
||||
|
||||
|
||||
<section class="contact-form-area py-120 rel z-1">
|
||||
<div class="container">
|
||||
<div class="row align-items-center">
|
||||
<!-- <div class="col-lg-6">
|
||||
<div style="text-align: center;">
|
||||
<img style="width:400px;" src="assets/images/logos/weblogo.png" alt="About">
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="">
|
||||
<div class="comment-form bgc-lighter z-1 rel mb-30 rmb-55">
|
||||
<form id="loginForm" class="loginForm" name="loginForm" action="validate_login" method="post" data-aos="fade-left" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="section-title">
|
||||
<h2>Log in</h2>
|
||||
<div style="text-align: center;" id="responseMessage"></div> <!-- Message display area -->
|
||||
</div>
|
||||
|
||||
<!-- Google login button -->
|
||||
<div class="row mt-35">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<a href="<?php echo $login_url; ?>" style="width:100%;" class="theme-btn style-three">
|
||||
<img src="/assets/images/google.png" alt="Google Icon" style="width:20px; height:20px; margin-right: 10px; vertical-align: middle;">
|
||||
Login with Google
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="text-align: center; margin: 20px 0;">
|
||||
<!-- <hr style="border: 1px solid #ddd; width: 50%; margin: 0 auto;"> -->
|
||||
<span style="top: -10px; padding: 0 10px;">or</span>
|
||||
</div>
|
||||
|
||||
<!-- Email login fields -->
|
||||
<div class="row mt-35">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="email">Email Address</label>
|
||||
<input type="email" id="email" name="email" class="form-control" placeholder="Enter Email" value="" required data-error="Please enter a valid Email address">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12"></div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" class="form-control" placeholder="Enter Password" value="" required data-error="Please enter your password">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="form-group mb-0">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo generateCSRFToken(); ?>">
|
||||
<button type="submit" class="theme-btn style-two" style="width:100%;">Log In</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pt-20" style="text-align: center;">Don't have an account? <a href="register"><b>Register here.</b> </a>| <a href="forgot_password"><b>Forgot your password?</b></a></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Contact Form Area end -->
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#loginForm').on('submit', function(event) {
|
||||
event.preventDefault(); // Prevent the default form submission
|
||||
|
||||
$.ajax({
|
||||
url: '<?= url("validate_login") ?>',
|
||||
type: 'POST',
|
||||
data: $(this).serialize(),
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
window.location.href = '<?= url("index") ?>';
|
||||
} else {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">An error occurred while processing your request.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include_once($rootPath . '/components/insta_footer.php'); ?>
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
$headerStyle = 'light';
|
||||
include_once(dirname(dirname(dirname(__DIR__))) . '/header.php') ?>
|
||||
<style>
|
||||
@media (min-width: 991px) {
|
||||
.container {
|
||||
max-width: 720px;
|
||||
padding: 0 15px;
|
||||
}
|
||||
}
|
||||
|
||||
#passwordRequirements li {
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.text-success {
|
||||
color: green !important;
|
||||
}
|
||||
|
||||
.text-danger {
|
||||
color: red !important;
|
||||
}
|
||||
</style>
|
||||
<!-- Contact Form Area start -->
|
||||
<section class="contact-form-area py-70 rel z-1">
|
||||
<div class="container">
|
||||
<div class="row align-items-center">
|
||||
<div class="">
|
||||
<div class="comment-form bgc-lighter z-1 rel mb-30 rmb-55">
|
||||
<form id="registerForm" name="registerForm" action="register_user" method="post" data-aos="fade-left" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="section-title">
|
||||
<h2>Register</h2>
|
||||
|
||||
</div>
|
||||
<p>Register to create your 4WDCSA.co.za user profile.</p>
|
||||
<div class="row mt-35">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="first_name">First Name</label>
|
||||
<input type="text" id="first_name" name="first_name" class="form-control" placeholder="John" value="" required data-error="Please enter your Name">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="last_name">Last Name</label>
|
||||
<input type="text" id="last_name" name="last_name" class="form-control" placeholder="Smith" value="" required data-error="Please enter your Last Name">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="phone_number">Phone Number</label>
|
||||
<input type="text" id="phone_number" name="phone_number" class="form-control" placeholder="Phone" value="" required data-error="Please enter your Phone">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="email">Email Address</label>
|
||||
<input type="email" id="email" name="email" class="form-control" placeholder="Enter email" value="" required data-error="Please enter your Email">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" class="form-control" placeholder="Enter password" value="" required data-error="Please enter your password">
|
||||
<ul id="passwordRequirements" class="small mt-2" style="list-style: none; padding-left: 0;">
|
||||
<li id="length" class="text-danger">✗ At least 8 characters</li>
|
||||
<li id="uppercase" class="text-danger">✗ At least one uppercase letter</li>
|
||||
<li id="lowercase" class="text-danger">✗ At least one lowercase letter</li>
|
||||
<li id="number" class="text-danger">✗ At least one number</li>
|
||||
<li id="special" class="text-danger">✗ At least one special character</li>
|
||||
</ul>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="password_confirm">Confirm Password</label>
|
||||
<input type="password" id="password_confirm" name="password_confirm" class="form-control" placeholder="Enter password" value="" required data-error="Please enter your password">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group mb-0">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo generateCSRFToken(); ?>">
|
||||
<button type="submit" class="theme-btn style-two" style="width:100%;">Register</button>
|
||||
<div id="msgSubmit" class="hidden"></div>
|
||||
</div>
|
||||
<div id="responseMessage"></div> <!-- Message display area -->
|
||||
</div>
|
||||
<div class="pt-20">Already have an account? <a href="login"><b>Log in here.</b></a></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Contact Form Area end -->
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script>
|
||||
function updatePasswordFeedback(password) {
|
||||
const length = password.length >= 8;
|
||||
const uppercase = /[A-Z]/.test(password);
|
||||
const lowercase = /[a-z]/.test(password);
|
||||
const number = /[0-9]/.test(password);
|
||||
const special = /[\W_]/.test(password);
|
||||
|
||||
$('#length').toggleClass('text-success', length).toggleClass('text-danger', !length).html(`${length ? '✓' : '✗'} At least 8 characters`);
|
||||
$('#uppercase').toggleClass('text-success', uppercase).toggleClass('text-danger', !uppercase).html(`${uppercase ? '✓' : '✗'} At least one uppercase letter`);
|
||||
$('#lowercase').toggleClass('text-success', lowercase).toggleClass('text-danger', !lowercase).html(`${lowercase ? '✓' : '✗'} At least one lowercase letter`);
|
||||
$('#number').toggleClass('text-success', number).toggleClass('text-danger', !number).html(`${number ? '✓' : '✗'} At least one number`);
|
||||
$('#special').toggleClass('text-success', special).toggleClass('text-danger', !special).html(`${special ? '✓' : '✗'} At least one special character`);
|
||||
}
|
||||
|
||||
$('#password').on('input', function() {
|
||||
const password = $(this).val();
|
||||
updatePasswordFeedback(password);
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#registerForm').on('submit', function(event) {
|
||||
event.preventDefault(); // Prevent default form submission
|
||||
|
||||
const password = $('#password').val();
|
||||
const confirmPassword = $('#password_confirm').val();
|
||||
const passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$/;
|
||||
|
||||
if (!passwordPattern.test(password)) {
|
||||
$('#responseMessage').html(`
|
||||
<div class="alert alert-danger">
|
||||
Password must be at least 8 characters long, include uppercase and lowercase letters, a number, and a special character.
|
||||
</div>
|
||||
`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
$('#responseMessage').html(`
|
||||
<div class="alert alert-danger">Passwords do not match.</div>
|
||||
`);
|
||||
return;
|
||||
}
|
||||
|
||||
// If validation passes, proceed with AJAX
|
||||
$.ajax({
|
||||
url: 'register_user',
|
||||
type: 'POST',
|
||||
data: $(this).serialize(),
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status === 'success') {
|
||||
$('#responseMessage').html('<div class="alert alert-success">' + response.message + '</div>');
|
||||
$('#registerForm')[0].reset(); // Optionally reset the form
|
||||
} else {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">An error occurred while processing your request.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<?php include_once(dirname(dirname(dirname(__DIR__))) . '/components/insta_footer.php'); ?>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
require_once($rootPath . '/src/config/connection.php');
|
||||
require_once($rootPath . '/src/config/functions.php');
|
||||
require_once($rootPath . '/vendor/autoload.php');
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($data['email'], $data['name'], $data['token'])) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Missing required fields.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $data['email'];
|
||||
$name = $data['name'];
|
||||
$token = $data['token'];
|
||||
|
||||
|
||||
if (sendVerificationEmail($email, $name, $token)) {
|
||||
$_SESSION['message'] = "Verification mail resend successful!";
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => "Verification email sent to $email."
|
||||
]);
|
||||
} else {
|
||||
$_SESSION['message'] = "Verification mail resend FAILED!";
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => "Failed to send verification email to $email."
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
$headerStyle = 'light';
|
||||
include_once(dirname(dirname(dirname(__DIR__))) . '/header.php');
|
||||
$token = $_GET['token'] ?? '';
|
||||
|
||||
if (empty($token)) {
|
||||
die("Invalid token.");
|
||||
}
|
||||
|
||||
// Verify the token
|
||||
$sql = "SELECT user_id FROM password_resets WHERE token = ? AND expires_at > NOW()";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("s", $token);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows === 0) {
|
||||
die("Token is invalid or expired.");
|
||||
}
|
||||
|
||||
$user = $result->fetch_assoc();
|
||||
$user_id = $user['user_id'];
|
||||
|
||||
// Display the reset password form
|
||||
?>
|
||||
|
||||
<style>
|
||||
@media (min-width: 991px) {
|
||||
.container {
|
||||
max-width: 720px;
|
||||
padding: 0 15px; /* Ensure padding doesn't cause overflow */
|
||||
}
|
||||
</style>
|
||||
<!-- Contact Form Area start -->
|
||||
<section class="contact-form-area py-120 rel z-1">
|
||||
<div class="container">
|
||||
<div class="row align-items-center">
|
||||
|
||||
|
||||
<div class="">
|
||||
<div class="comment-form bgc-lighter z-1 rel mb-30 rmb-55">
|
||||
<form id="changePasswordForm" class="loginForm" name="changePasswordForm" action="update_password" method="post" data-aos="fade-left" data-aos-duration="1500" data-aos-offset="50">
|
||||
<div class="section-title">
|
||||
<h2>Reset Password</h2>
|
||||
<div class="pt-20" style="text-align: center;" id="responseMessage"></div> <!-- Message display area -->
|
||||
</div>
|
||||
<div class="row mt-35">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="new_password">New Password</label>
|
||||
<input type="password" id="new_password" name="new_password" class="form-control" placeholder="Enter password" value="" required data-error="Please enter your password">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="confirm_password">Confirm Password</label>
|
||||
<input type="password" id="confirm_password" name="confirm_password" class="form-control" placeholder="Confirm password" value="" required data-error="Please confirm your password">
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="form-group mb-0">
|
||||
<input type="hidden" name="token" value="<?php echo htmlspecialchars($token); ?>">
|
||||
<button type="submit" class="theme-btn style-two" style="width:100%;">Reset Password</button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Contact Form Area end -->
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Change Password
|
||||
$('#changePasswordForm').on('submit', function(event) {
|
||||
event.preventDefault(); // Prevent default form submission
|
||||
|
||||
$.ajax({
|
||||
url: 'update_password',
|
||||
type: 'POST',
|
||||
data: $(this).serialize(),
|
||||
success: function(response) {
|
||||
// Parse response if needed
|
||||
if (typeof response === "string") {
|
||||
response = JSON.parse(response);
|
||||
}
|
||||
|
||||
if (response.status === 'success') {
|
||||
$('#responseMessage').html('<div class="alert alert-success">' + response.message + '</div>');
|
||||
} else {
|
||||
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#responseMessage2').html('<div class="alert alert-danger">Error changing password.</div>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include_once(dirname(dirname(dirname(__DIR__))) . '/components/insta_footer.php'); ?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
require_once($rootPath . '/src/config/env.php');
|
||||
require_once($rootPath . '/src/config/connection.php');
|
||||
require_once($rootPath . '/src/config/functions.php');
|
||||
|
||||
$response = array('status' => 'error', 'message' => 'Something went wrong');
|
||||
|
||||
if (isset($_POST['token'], $_POST['new_password'], $_POST['confirm_password'])) {
|
||||
$token = $_POST['token'];
|
||||
$new_password = $_POST['new_password'];
|
||||
$confirm_password = $_POST['confirm_password'];
|
||||
|
||||
if ($new_password !== $confirm_password) {
|
||||
$response['message'] = 'Passwords do not match.';
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Verify the token
|
||||
$sql = "SELECT user_id FROM password_resets WHERE token = ? AND expires_at > NOW()";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("s", $token);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows === 0) {
|
||||
$response['message'] = 'Token is invalid or expired.';
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
|
||||
$user = $result->fetch_assoc();
|
||||
$user_id = $user['user_id'];
|
||||
|
||||
// Hash the new password
|
||||
$new_password_hash = password_hash($new_password, PASSWORD_BCRYPT);
|
||||
|
||||
// Update the new password in the database
|
||||
$sql = "UPDATE users SET password = ? WHERE user_id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("si", $new_password_hash, $user_id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
// Delete the token from the database
|
||||
$sql = "DELETE FROM password_resets WHERE token = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("s", $token);
|
||||
$stmt->execute();
|
||||
|
||||
$response['status'] = 'success';
|
||||
$response['message'] = 'Password has been successfully reset.';
|
||||
} else {
|
||||
$response['message'] = 'Failed to reset password.';
|
||||
}
|
||||
} else {
|
||||
$response['message'] = 'Invalid form submission.';
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
?>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
$rootPath = dirname(dirname(dirname(__DIR__)));
|
||||
require_once($rootPath . '/src/config/env.php');
|
||||
require_once($rootPath . '/src/config/connection.php');
|
||||
require_once($rootPath . '/src/config/functions.php');
|
||||
|
||||
// Create connection
|
||||
$conn = openDatabaseConnection();
|
||||
|
||||
// Check connection
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
// Verify token
|
||||
if (isset($_GET['token'])) {
|
||||
$token = $conn->real_escape_string($_GET['token']);
|
||||
|
||||
// Prepare and execute query
|
||||
$stmt = $conn->prepare('UPDATE users SET is_verified = 1 WHERE token = ?');
|
||||
$stmt->bind_param('s', $token);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
if ($stmt->affected_rows > 0) {
|
||||
header('Location: login.php');
|
||||
} else {
|
||||
header('Location: login.php');
|
||||
}
|
||||
} else {
|
||||
echo 'Error: ' . $stmt->error;
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
} else {
|
||||
echo 'No token provided.';
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user