From 544ac2744e5e7f4fffc419b8e798160c3155b322 Mon Sep 17 00:00:00 2001 From: UBC Student Date: Wed, 19 Jun 2024 02:59:08 -0700 Subject: [PATCH] login and signup is working properly, with 2-factor authentication --- project/login_pages/login.php | 98 +++++++++---------- .../login_pages/{navbar.php => navbar.html} | 0 project/login_pages/signup.php | 72 +++++++++----- project/login_pages/signup_form.php | 2 +- project/login_pages/test_db.php | 59 +++++++++++ project/login_pages/welcome.php | 2 +- 6 files changed, 156 insertions(+), 77 deletions(-) rename project/login_pages/{navbar.php => navbar.html} (100%) create mode 100755 project/login_pages/test_db.php diff --git a/project/login_pages/login.php b/project/login_pages/login.php index 8a3a983..6ef2b2e 100755 --- a/project/login_pages/login.php +++ b/project/login_pages/login.php @@ -13,43 +13,57 @@ function isValidEmail($email) { function emailExists($email){ global $db_conn; if (connectToDB()) { - echo "connect to DB success"; // Added missing semicolon - $result = executePlainSQL("SELECT * FROM CUSTOMER WHERE EMAIL = '{$email}'"); - if ($result) { - $row = oci_fetch_array($result, OCI_ASSOC); - disconnectFromDB(); - return $row != false; + echo "Connected to DB successfully.
"; // Debug message + $escaped_email = htmlspecialchars($email, ENT_QUOTES, 'UTF-8'); + $query = "SELECT * FROM CUSTOMER WHERE EMAIL = :email"; + $statement = oci_parse($db_conn, $query); + oci_bind_by_name($statement, ':email', $escaped_email); + + if (oci_execute($statement)) { + if ($row = oci_fetch_array($statement, OCI_ASSOC)) { + echo "Email exists in the database.
"; // Debug message + oci_free_statement($statement); + disconnectFromDB(); + return true; + } else { + echo "Email does not exist in the database.
"; // Debug message + oci_free_statement($statement); + disconnectFromDB(); + return false; + } } else { - echo "Database query failed."; + echo "Database query execution failed.
"; // Debug message + oci_free_statement($statement); disconnectFromDB(); return false; } } else { - echo "Database connection failed."; + echo "Database connection failed.
"; // Debug message return false; } } if ($_SERVER["REQUEST_METHOD"] == "POST") { $email = $_POST['email/phone']; + + echo "Form submitted.
"; // Debug message + echo "Email entered: $email
"; // Debug message if (isValidEmail($email)) { + echo "Email is valid.
"; // Debug message + if (emailExists($email)) { - echo "Success"; - // header("Location: ../user_pages/user_homepage.php"); - disconnectFromDB(); + echo "Redirecting to user homepage.
"; // Debug message + header("Location: ../user_pages/user_homepage.php"); exit(); } else { - echo "Email does not exist."; + echo "Email does not exist.
"; // Debug message } } else { - echo "Invalid email address."; + echo "Invalid email address.
"; // Debug message } } -?> - - - +?> @@ -57,12 +71,10 @@ function emailExists($email){ MealMate - - @@ -201,19 +203,13 @@ function emailExists($email){

What's your phone number or email?

- -
" method="POST" style="width: 100%; display: flex; flex-direction: column; align-items: center;">
- -

or
- - - -
- - - + diff --git a/project/login_pages/navbar.php b/project/login_pages/navbar.html similarity index 100% rename from project/login_pages/navbar.php rename to project/login_pages/navbar.html diff --git a/project/login_pages/signup.php b/project/login_pages/signup.php index 199aa87..80f15c3 100755 --- a/project/login_pages/signup.php +++ b/project/login_pages/signup.php @@ -1,6 +1,12 @@ + -?> @@ -96,7 +118,7 @@ function sendVerificationEmail($email, $code) { } .top-bar .logo { - height: 50px; /* Adjust the height as needed */ + height: 50px; width: auto; } @@ -207,8 +229,9 @@ function sendVerificationEmail($email, $code) { +
-

What's your email?

+

What's your phone number or email?

" method="POST" style="width: 100%; display: flex; flex-direction: column; align-items: center;"> @@ -247,3 +270,8 @@ function sendVerificationEmail($email, $code) { + + + + + diff --git a/project/login_pages/signup_form.php b/project/login_pages/signup_form.php index 50bdeb0..3830779 100755 --- a/project/login_pages/signup_form.php +++ b/project/login_pages/signup_form.php @@ -1,7 +1,7 @@ diff --git a/project/login_pages/test_db.php b/project/login_pages/test_db.php new file mode 100755 index 0000000..9cbadf6 --- /dev/null +++ b/project/login_pages/test_db.php @@ -0,0 +1,59 @@ +"; // Debug message + $query = "SELECT * FROM CUSTOMER WHERE EMAIL = :email"; + $email = 'test@example.com'; // Replace with a test email that exists in your database + $escaped_email = htmlspecialchars($email, ENT_QUOTES, 'UTF-8'); + $statement = oci_parse($db_conn, $query); + oci_bind_by_name($statement, ':email', $escaped_email); + + if (oci_execute($statement)) { + if ($row = oci_fetch_array($statement, OCI_ASSOC)) { + echo "Email found: " . $row['EMAIL'] . "
"; // Debug message + oci_free_statement($statement); + disconnectFromDB(); + return true; + } else { + echo "Email not found.
"; // Debug message + oci_free_statement($statement); + disconnectFromDB(); + return false; + } + } else { + echo "Database query execution failed.
"; // Debug message + oci_free_statement($statement); + disconnectFromDB(); + return false; + } + } else { + echo "Database connection failed.
"; // Debug message + return false; + } +} + +testDatabaseConnection(); +?> + + + + + + + MealMate + + +

This is a test page

+ + + + + + + + + + diff --git a/project/login_pages/welcome.php b/project/login_pages/welcome.php index 2ed0586..586bd37 100755 --- a/project/login_pages/welcome.php +++ b/project/login_pages/welcome.php @@ -1,4 +1,4 @@ - +