Implementation of Notification System

This commit is contained in:
twotalesanimation
2025-12-16 22:40:24 +02:00
parent ebd7efe21c
commit 7ebc2f64cf
18 changed files with 501 additions and 232 deletions

View File

@@ -5,6 +5,8 @@ require_once($rootPath . "/src/config/session.php");
require_once($rootPath . "/src/config/connection.php");
require_once($rootPath . "/src/config/functions.php");
require_once($rootPath . '/google-client/vendor/autoload.php'); // Add this line for Google Client
require_once($rootPath . "/src/helpers/notification_helper.php");
// Check if connection is established
if (!$conn) {
@@ -37,6 +39,8 @@ if (isset($_GET['code'])) {
$last_name = $google_account_info->family_name;
$picture = $google_account_info->picture;
// Check if the user exists in the database
$query = "SELECT * FROM users WHERE email = ?";
$stmt = $conn->prepare($query);
@@ -53,12 +57,20 @@ if (isset($_GET['code'])) {
$stmt->bind_param("sssssi", $email, $first_name, $last_name, $picture, $password, $is_verified);
if ($stmt->execute()) {
// User successfully registered, set session and redirect
sendEmail('chrispintoza@gmail.com', '4WDCSA: New User Login', $name.' has just created an account using Google Login.');
$_SESSION['user_id'] = $conn->insert_id;
$_SESSION['first_name'] = $first_name;
$_SESSION['profile_pic'] = $picture;
processLegacyMembership($_SESSION['user_id']);
// echo json_encode(['status' => 'success', 'message' => 'Google login successful']);
// Send Notification
$event = 'user_login';
$sub_feed = 'logins';
$data = [
'actor_id' => $conn->insert_id,
'actor_avatar' => $picture, // used by UI to show avatar
'title' => "User Login by {$first_name} {$last_name}"
];
addNotification(null, $event, $sub_feed, $data, null);
header("Location: index.php");
exit();
} else {
@@ -72,8 +84,17 @@ if (isset($_GET['code'])) {
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['profile_pic'] = $row['profile_pic'];
sendEmail('chrispintoza@gmail.com', '4WDCSA: New User Login', $name.' has just logged in using Google Login.');
// echo json_encode(['status' => 'success', 'message' => 'Google login successful']);
// Send Notification
$event = 'user_login';
$sub_feed = 'logins';
$data = [
'actor_id' => $_SESSION['user_id'],
'actor_avatar' => $_SESSION['profile_pic'], // used by UI to show avatar
'title' => "User Login by {$first_name} {$last_name}"
];
addNotification(null, $event, $sub_feed, $data, null);
header("Location: index.php");
exit();
}
@@ -181,6 +202,16 @@ if (isset($_POST['email']) && isset($_POST['password'])) {
// Set session timeout (30 minutes)
$_SESSION['login_time'] = time();
$_SESSION['session_timeout'] = 1800; // 30 minutes in seconds
// Send Notification
$event = 'user_login';
$sub_feed = 'logins';
$data = [
'actor_id' => $_SESSION['user_id'],
'actor_avatar' => $_SESSION['profile_pic'], // used by UI to show avatar
'title' => "User Login by {$first_name} {$last_name}"
];
addNotification(null, $event, $sub_feed, $data, null);
auditLog($row['user_id'], 'LOGIN_SUCCESS', 'users', $row['user_id']);
echo json_encode(['status' => 'success', 'message' => 'Successful Login']);