From 5d1761b19d5b2f618d76862d4cc0d24ab5bd7bfe Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 28 Feb 2016 14:52:54 -0500 Subject: [PATCH] Implemented password checking Currently allows anything for the password. This will be updated when I implment passwords on the main repo. --- list.php | 66 +++++++++++++++++++++++++++++++++++++++-------- php/add.php | 7 ++++- php/checkPass.php | 10 +++++++ php/functions.php | 5 ++++ php/sub.php | 7 ++++- 5 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 php/checkPass.php create mode 100644 php/functions.php diff --git a/list.php b/list.php index c0a0cf52..8087f20f 100644 --- a/list.php +++ b/list.php @@ -47,14 +47,17 @@ function getFullName() { @@ -115,8 +118,10 @@ require "footer.php"; $.ajax({ url: "php/add.php", method: "get", - data: {"domain":domain, "list":""}, + data: {"domain":domain, "list":"", "pass":password}, success: function(response) { + if(response.length !== 0) + return; document.getElementById("alSuccess").hidden = false; refresh(); }, @@ -133,8 +138,10 @@ require "footer.php"; $.ajax({ url: "php/sub.php", method: "get", - data: {"domain":entry, "list":""}, + data: {"domain":entry, "list":"", "pass":password}, success: function(response) { + if(response.length !== 0) + return; document.getElementById("list").removeChild(document.getElementById(index)); }, error: function(jqXHR, exception) { @@ -145,24 +152,61 @@ require "footer.php"; } function getPassword(callback) { - // Return if we already have the password + // Check password and return if(password.length !== 0) { - callback(); + $.ajax({ + url: "php/checkPass.php", + method: "get", + data: {"pass":password}, + success: function(response) { + if(response === "Correct") + callback(); + }, + error: function(jqXHR, exception) { + alert("Failed to check password!"); + } + }); return; } // Prompt the user for password - $("#passModal").modal(); + var modal = $("#passModal"); + modal.modal(); // Handle enter button $("#passBtn").on("click", function() { var passInput = $("#passInput"); + var passAlert = $("#alPassword"); password = passInput.val(); - passInput.html(""); - // Execute callback if password was entered - if(password.length !== 0) - callback(); + // Execute callback if entered + if(password.length !== 0) { + // Check if password is correct + $.ajax({ + url: "php/checkPass.php", + method: "get", + data: {"pass":password}, + success: function(response) { + if(response === "Correct") { + passInput.html(""); + passAlert.hide(); + modal.modal("hide"); + callback(); + } + else { + passAlert.show(); + password = ""; + } + }, + error: function(jqXHR, exception) { + alert("Failed to check password!"); + password = ""; + } + }); + } + else { + passAlert.show() + } }); } diff --git a/php/add.php b/php/add.php index 95585ee7..c602119d 100644 --- a/php/add.php +++ b/php/add.php @@ -1,7 +1,12 @@