Skip to content

Commit

Permalink
Merges gh-pages to master
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijitkr committed Dec 29, 2023
2 parents daad7bf + 88c9298 commit c4399c8
Show file tree
Hide file tree
Showing 20 changed files with 1,299 additions and 150 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TODO-WebApplication

You can access this project through the given link [TODO-Web App](https://myawesometodo.000webhostapp.com/).
35 changes: 35 additions & 0 deletions add_todo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
session_start();
require_once 'db_connect.php';

// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
$response = array('success' => false, 'message' => 'User not logged in.');
echo json_encode($response);
exit();
}

// Prepare the SQL statement
$stmt = $mysqli->prepare("INSERT INTO todos (user_id, item) VALUES (?, ?)");
$stmt->bind_param("is", $_SESSION['user_id'], $_POST['item']);

// Execute the statement
$success = $stmt->execute();

// Get the ID of the inserted row
$itemId = $stmt->insert_id;

// Close the statement and database connection
$stmt->close();
$mysqli->close();

// Prepare the response
if ($success) {
$response = array('success' => true, 'itemId' => $itemId);
} else {
$response = array('success' => false, 'message' => 'Failed to add the todo.');
}

// Return the response as JSON
echo json_encode($response);
?>
15 changes: 15 additions & 0 deletions db_connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
// Database credentials
$host = 'localhost'; // Replace with your host name
$dbUsername = 'root'; // Replace with your database username
$dbPassword = ''; // Replace with your database password
$dbName = 'todo'; // Replace with your database name

// Create a new MySQLi object and establish the connection
$mysqli = new mysqli($host, $dbUsername, $dbPassword, $dbName);

// Check the connection
if ($mysqli->connect_error) {
die('Connect Error: ' . $mysqli->connect_error);
}
?>
36 changes: 36 additions & 0 deletions edit_todo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
// Check if the ID and newText parameters are provided
if (isset($_POST['id']) && isset($_POST['newText']) && !empty(trim($_POST['newText']))) {
// Retrieve the values from the request
$itemId = $_POST['id'];
$newText = $_POST['newText'];

require_once 'db_connect.php';

// Prepare and execute the update statement
$stmt = $mysqli->prepare("UPDATE todos SET item = ? WHERE id = ?");
$stmt->bind_param("si", $newText, $itemId);

// Check if the update value is not empty
if (!empty($newText)) {
$stmt->execute();
}
// Check if the update was successful
if ($stmt->affected_rows > 0) {
$response = array("success" => true);
} else {
$response = array("success" => false, "message" => "Failed to update the todo.");
}

// Close the prepared statement and database connection
$stmt->close();
$mysqli->close();

// Return the response as JSON
echo json_encode($response);
} else {
// If the ID or newText parameters are missing, return an error response
$response = array("success" => false, "message" => "Invalid request.");
echo json_encode($response);
}

38 changes: 38 additions & 0 deletions fetch_todos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
session_start();
require_once 'db_connect.php';

// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
// Redirect to the login page or handle the unauthorized access as per your requirements
echo "<script>alert('You are not logged in.');</script>";
echo "<script>window.location.href = 'login.php';</script>";
exit();
}

// Fetch todos for the logged-in user
$user_id = $_SESSION['user_id'];

// Prepare the SQL statement
$stmt = $mysqli->prepare("SELECT * FROM todos WHERE user_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();

// Fetch all todo items for the user
$todos = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$todos[] = $row;
}
}

// Close the statement and database connection
$stmt->close();
$mysqli->close();

// Return the todos as a JSON response
$response = array('success' => true, 'todos' => $todos);
header('Content-Type: application/json'); // Set the response header as JSON
echo json_encode($response);
?>
38 changes: 0 additions & 38 deletions index.html

This file was deleted.

49 changes: 49 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Awesome Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<style>
body, html {
height: 100%;
}
.full-screen {
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.jumbotron {
background-color: #333;
color: #fff;
padding: 50px;
text-align: center;
}
.display-4 {
font-size: 3rem;
margin-bottom: 30px;
}
.buttons {
margin-top: 30px;
}
</style>
</head>
<body>
<div class="full-screen">
<div class="jumbotron">
<h1 class="display-4">Welcome to the Awesome Page</h1>
<div class="buttons">
<a href="register.php" class="btn btn-primary btn-lg mr-3">Sign Up</a>
<a href="signin.php" class="btn btn-secondary btn-lg">Log In</a>
</div>
</div>
</div>
</body>
</html>
20 changes: 20 additions & 0 deletions landing.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
body {
background-color: #f5f5f5;
}

.jumbotron {
background-color: #333;
color: #fff;
height: 100vh;
margin-bottom: 0;
}

.display-4 {
font-size: 3rem;
margin-top: 200px;
}

.buttons {
margin-top: 50px;
}

34 changes: 34 additions & 0 deletions login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
session_start();
require_once 'db_connect.php';

if (isset($_POST['email']) && isset($_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];

if (!empty($email) && !empty($password)) {
$stmt = $mysqli->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();

if ($user && password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id']; // Store the user_id in the session

echo "<script>alert('Login successful!');</script>";
echo "<script>window.location.href = 'todolist.php';</script>";
exit();
} else {
echo "<script>alert('Invalid email or password.');</script>";
echo "<script>window.location.href = 'signin.php';</script>";
}

} else {
echo "<script>alert('Please fill in all the required fields.');</script>";
echo "<script>window.location.href = 'signin.php';</script>";
}
$stmt->close();
$mysqli->close();
}
?>
13 changes: 13 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
session_start(); // Start the session

// Clear all session data
session_unset();

// Destroy the session
session_destroy();

// Redirect the user to the login page
header("Location: signin.php");
exit();
?>
Loading

0 comments on commit c4399c8

Please sign in to comment.