Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
419 changes: 241 additions & 178 deletions dashboard.php

Large diffs are not rendered by default.

127 changes: 68 additions & 59 deletions includes/header.php
Original file line number Diff line number Diff line change
@@ -1,74 +1,83 @@
<nav id="header" class="fixed top-0 left-0 w-full border-gray-200">
<div class="max-w-full flex flex-wrap items-center justify-between mx-auto p-4">
<a href="index.php">
<span class="text-white self-center text-2xl font-semibold whitespace-nowrap dark:text-white flex">
<div id="img-container">
<img src="img/logo.png" />
</div>

<nav id="header" class="fixed top-0 left-0 w-full bg-yellow-400 border-gray-200">
<div class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
<a href="home.php">
<span class="text-white self-center text-2xl font-semibold whitespace-nowrap dark:text-white flex">
<div id="img-container">
<img src="img/logo.png"/>
</div>
<div id="name">
Attendance Tracker
</div>
</span>
</a>
<button data-collapse-toggle="navbar-default" type="button" class="inline-flex items-center p-2 w-10 h-10 justify-center text-sm rounded-lg md:hidden hover:bg-yellow-600 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-red-700 dark:hover:bg-yellow-600 dark:focus:ring-gray-600" aria-controls="navbar-default" aria-expanded="false">
<span class="sr-only">Open main menu</span>
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 17 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h15M1 7h15M1 13h15"/>
</svg>
</button>
<div class="hidden w-full md:block md:w-auto" id="navbar-default">
<?php
//if the USER is logged in
if(isset($_SESSION['user_id'])){
?>
<ul class="bg-yellow-500 font-medium flex flex-col p-2 md:p-0 mt-1 border border-gray-100 rounded-lg bg-gray-50 md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0 md:bg-yellow-500 dark:bg-yellow-500 md:dark:bg-yellow-500">
<li class="flex items-center justify-center">
Hi, <?= $_SESSION['name']?>
</li>
<li>
<a href="logout.php" class="block py-2 px-3 text-white rounded hover:bg-yellow-700 md:hover:bg-yellow-700 md:border-0 md:hover:text-white md:p-0 dark:text-white md:dark:hover:text-white dark:hover:bg-yellow-700 dark:hover:text-white md:dark:hover:bg-yellow-700"><i class="fas fa-sign-out-alt"></i> Logout</a>
</li>
</ul>

<?php
}
//check if the ADMIN is logged in
elseif(isset($_SESSION['admin_id'])){
?>
<ul class="font-medium flex flex-col p-2 md:p-0 mt-1 border border-gray-100 rounded-lg bg-yellow-500 md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0 md:bg-yellow-500 dark:bg-yellow-500 md:dark:bg-yellow-500">
<li class="flex items-center justify-center">
<i class="fa fa-unlock-alt"></i> <?= $_SESSION['admin_name']?>
</li>
<li>
<a href="logout.php" class="block py-2 px-3 text-white rounded hover:bg-yellow-700 md:hover:bg-yellow-700 md:border-0 md:hover:text-white md:p-0 dark:text-white md:dark:hover:text-white dark:hover:bg-yellow-700 dark:hover:text-white md:dark:hover:bg-yellow-700"><i class="fas fa-sign-out-alt"></i> Logout</a>
</li>
</ul>

<?php
}
<div id="name" class="text-3xl">
Attendance Tracker
</div>
</span>
</a>
<button data-collapse-toggle="navbar-default" type="button"
class="inline-flex items-center p-2 w-10 h-10 justify-center text-sm rounded-lg md:hidden focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-red-700 dark:focus:ring-gray-600"
aria-controls="navbar-default" aria-expanded="false">
<span class="sr-only">Open main menu</span>
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 17 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M1 1h15M1 7h15M1 13h15" />
</svg>
</button>

else {
?>
<ul class="font-medium flex flex-col p-2 md:p-0 mt-1 border border-gray-100 rounded-lg bg-yellow-500 md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0 md:bg-yellow-500 dark:bg-yellow-500 md:dark:bg-yellow-500">
<div class="hidden w-full md:block md:w-auto" id="navbar-default">
<?php
//if the USER is logged in
if (isset($_SESSION['user_id'])) {
?>
<ul
class="font-medium flex flex-col p-2 md:p-0 mt-1 md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0">
<li class="text-xl flex items-center justify-center">
Hi, <?= $_SESSION['name'] ?>
</li>
<li>
<a data-modal-target="signup-modal" data-modal-toggle="signup-modal" href="#" class="block py-2 px-3 text-white rounded hover:bg-yellow-700 md:bg-transparent md:text-blue-500 md:p-0 dark:text-white md:dark:text-blue-500"><i class="fas fa-user"></i> Signup</a>
<a href="logout.php" class="text-xl block py-2 px-3 text-black md:border-0 md:p-0"><i
class="fas fa-sign-out-alt"></i> Logout</a>
</li>
</ul>

<?php
}
//check if the ADMIN is logged in
elseif (isset($_SESSION['admin_id'])) {
?>
<ul
class="font-medium flex flex-col p-2 md:p-0 mt-1 border border-gray-100 rounded-lg md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0">
<li class="text-2xl flex items-center justify-center">
<i class="fa fa-unlock-alt"></i> <?= $_SESSION['admin_name'] ?>
</li>
<li>
<a data-modal-target="authentication-modal" data-modal-toggle="authentication-modal" href="#" class="block py-2 px-3 text-white rounded hover:bg-yellow-700 md:hover:bg-yellow-700 md:border-0 md:hover:text-white md:p-0 dark:text-white md:dark:hover:text-white dark:hover:bg-yellow-700 dark:hover:text-white md:dark:hover:bg-yellow-700"><i class="fas fa-sign-in-alt"></i> Login</a>
<a href="logout.php"
class="text-2xl block py-2 px-3 text-white rounded md:border-0 md:hover:text-white md:p-0 dark:text-white md:dark:hover:text-white dark:hover:text-white "><i
class="fas fa-sign-out-alt"></i> Logout</a>
</li>
</ul>

<?php
}
} else {
?>
</div>
</div>
<ul
class="font-medium flex flex-col p-2 md:p-0 mt-1 md:flex-row md:space-x-4 rtl:space-x-reverse md:mt-0 md:border-0">
<li>
<a data-modal-target="signup-modal" data-modal-toggle="signup-modal" href="#"
class="text-2xl block py-2 px-3 hover:underline decoration-white decoration-solid text-white rounded md:bg-transparent md:text-blue-500 md:p-0 dark:text-white"><i
class="fas fa-user"></i> Signup</a>
</li>
<li>
<a data-modal-target="authentication-modal" data-modal-toggle="authentication-modal" href="#"
class="text-2xl block py-2 px-3 text-white hover:underline decoration-white decoration-solid md:border-0 md:hover:text-white md:p-0 dark:text-white md:dark:hover:text-white dark:hover:text-white"><i
class="fas fa-sign-in-alt"></i> Login</a>
</li>
</ul>
<?php
}
?>
</div>
</div>

</nav>


<?php
include "script.php";
?>


40 changes: 24 additions & 16 deletions includes/login.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<?php
header('Content-Type: application/json');
session_start();
require "../includes/database_connect.php";
require "./database_connect.php";

$email = $_POST['email'];
$password = $_POST['password'];
$password = sha1($password);
$sql = "SELECT * FROM users where email = '$email' AND password = '$password'";
$email = trim($_POST['email'] ?? '');
$password = trim($_POST['password'] ?? '');

if (empty($email) || empty($password)) {
echo json_encode(["success" => false, "message" => "Please enter both email and password."]);
exit;
}

$password_hashed = sha1($password);

$sql = "SELECT * FROM users WHERE email = '$email' AND password = '$password_hashed'";
$result = mysqli_query($conn, $sql);
if(!$result){
$response = array("success"=> false, "message"=> "Something went wrong!");
echo json_encode($response);
return;

if (!$result) {
echo json_encode(["success" => false, "message" => "Something went wrong. Please try again later."]);
exit;
}
$row_count = mysqli_num_rows($result);
if($row_count==0){
echo json_encode(array("success"=> false, "message"=> "Login failed! Invalid email or password"));
return;

if (mysqli_num_rows($result) === 0) {
echo json_encode(["success" => false, "message" => "Invalid email or password. Please try again."]);
exit;
}

$data = mysqli_fetch_assoc($result);
$_SESSION['user_id'] = $data['id'];
$_SESSION['name'] = $data['name'];
$_SESSION['email'] = $data['email'];

header("location: ../dashboard.php");
echo json_encode(["success" => true, "message" => "Login successful! Redirecting..."]);
mysqli_close($conn);

?>
?>
45 changes: 23 additions & 22 deletions includes/signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,37 @@
$email = $_POST['email'];
$password = $_POST['password'];
$re_password = $_POST['confirm-password'];

if($password != $re_password){
echo json_encode(array("success"=> false, "message"=> "Password not matched!"));
exit;
}
else {
$password = sha1($password);
$sql = "SELECT * FROM users where email = '$email'";
$result = mysqli_query($conn, $sql);
if(!$result){
$response = array("success"=> false, "message"=> "Something went wrong!");
$sql = "SELECT * FROM users where email = '$email'";
$result = mysqli_query($conn, $sql);
if (!$result) {
$response = array("success" => false, "message" => "Something went wrong!");
echo json_encode($response);
return;
}
$row_count = mysqli_num_rows($result);
if ($row_count != 0) {
$response = array("success" => false, "message" => "This email is already registered with us!");
echo json_encode($response);
return;
}
$sql_2 = "INSERT INTO users (name, email, password) values ('$name', '$email', '$password')";
$result_2 = mysqli_query($conn, $sql_2);
if (!$result_2) {
$response = array("success" => false, "message" => "Something went wrong!");
echo json_encode($response);
return;
}
$response = array("success" => true, "message" => "Your account has been created successfully! You can now log in to get started.");
echo json_encode($response);
return;
}
$row_count = mysqli_num_rows($result);
if($row_count!=0){
$response = array("success"=> false, "message"=> "This email is already registered with us!");
echo json_encode($response);
return;
}
$sql_2 = "INSERT INTO users (name, email, password) values ('$name', '$email', '$password')";
$result_2 = mysqli_query($conn, $sql_2);
if(!$result_2){
$response = array("success"=> false, "message"=> "Something went wrong!");
echo json_encode($response);
return;
}
$response = array("success"=> true, "message"=> "Your account has been created successfully!");
echo json_encode($response);
}

mysqli_close($conn);

?>
?>
Loading