Your one-time password is ' . $otp . '. This OTP is valid for 5 minutes.
This email is computer-generated, please do not reply.
'; + + // SMTP settings + $mail->isSMTP(); + $mail->Host = 'smtp.gmail.com'; // Replace with your SMTP server + $mail->SMTPAuth = true; + $mail->Username = 'erp.schoolmanagementsystem@gmail.com'; // Your SMTP username + $mail->Password = 'whqbysomdhdjthvr'; // Your SMTP password + $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; + $mail->Port = 587; + + // Email configuration + $mail->setFrom('erp.schoolmanagementsystem@gmail.com', 'Your App'); + $mail->addAddress($receiver); + $mail->isHTML(true); + $mail->Subject = $title; + $mail->Body = $message; + + return $mail; +} +?> diff --git a/index.js b/index.js index 975aae3..d272123 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ document.getElementById('confirmpassword').addEventListener('keyup', ()=>{ notMatch.style.display = 'none'; }); - +// Check data policy code is updated. (CL) function submitForm(event) { event.preventDefault(); @@ -61,7 +61,7 @@ function submitForm(event) { method: 'POST', body: formData }) - .then(response =>{ + .then(response => { if (!response.ok) { if (response.status === 500) { window.location.href = './errors/internal_server_error.html'; @@ -71,25 +71,33 @@ function submitForm(event) { return response.json(); }) .then(data => { - if(data.status === 'NO_CONNECTION'){ + if (data.status === 'NO_CONNECTION') { window.location.href = '../errors/error.html'; return; } - + error_msg.classList.remove('alert-danger', 'alert-success'); error_msg.classList.add(data.status === "success" ? 'alert-success' : 'alert-danger'); - error_msg.innerHTML = data.status === "success" ? 'success' : '' + data.message; - + error_msg.innerHTML = data.status === "success" ? 'success' : data.message; errorbox.style.display = 'block'; - - if (data.role === "admin") { - window.location.href = 'admin_panel/dashboard.php'; - } else if (data.role === "owner") { - window.location.href = 'owner_panel/index.php'; - } else if (data.role === "teacher") { - window.location.href = 'teacher_panel/dashboard.php'; - } else if (data.role === "student") { - window.location.href = 'student_panel/index.php'; + + // Check for a specific redirect page if provided in the response + if (data.status === 'redirect' && data.page) { + window.location.href = data.page; + return; + } + + // Redirect based on user role if login is successful + if (data.status === 'success') { + if (data.role === "admin") { + window.location.href = 'admin_panel/dashboard.php'; + } else if (data.role === "owner") { + window.location.href = 'owner_panel/index.php'; + } else if (data.role === "teacher") { + window.location.href = 'teacher_panel/dashboard.php'; + } else if (data.role === "student") { + window.location.href = 'student_panel/index.php'; + } } }) @@ -97,13 +105,13 @@ function submitForm(event) { console.error('Error:', error); error_msg.classList.remove('alert-success'); error_msg.classList.add('alert-danger'); - error_msg.innerHTML = 'Error ' + error.message; + error_msg.innerHTML = 'Error: ' + error.message; errorbox.style.display = 'block'; }); - } + document.getElementById('forgotpassword').addEventListener('click', function(){ hideLoginForm(true); hideVerifyOtpForm(true); @@ -481,4 +489,4 @@ function isStrongPassword() { confirmPassword.setAttribute('type', 'password'); label.innerHTML = 'Show password'; } - }); \ No newline at end of file + }); diff --git a/login-backend.php b/login-backend.php index fab8398..d9a57a6 100644 --- a/login-backend.php +++ b/login-backend.php @@ -29,11 +29,21 @@ $row = mysqli_fetch_assoc($result); if ($row) { - if (password_verify($password, $row['password_hash'])) { - $_SESSION['uid'] = $row['id']; - $response['status'] = 'success'; - $response['role'] = $row['role']; - } else { + // Check if the password matches (CL added) + if (password_verify($password, $row['password_hash'])) { + // Check the data policy + if ($row['data_policy'] == 0) { + // User has not accepted the data policy + $_SESSION['uid'] = $row['id']; + $response['status'] = 'redirect'; + $response['page'] = 'update_policy.php'; + } else { + // User has accepted the data policy, proceed with login + $_SESSION['uid'] = $row['id']; + $response['status'] = 'success'; + $response['role'] = $row['role']; + } + }else { $response['status'] = 'error'; $response['message'] = 'Invalid email or password!'; } diff --git a/otp.php b/otp.php new file mode 100644 index 0000000..f9cbb8f --- /dev/null +++ b/otp.php @@ -0,0 +1,111 @@ + + + + + +