-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,299 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
?> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
?> |
Oops, something went wrong.