From d54d7b37ea7fd3536432e03a5965d9461bdd2897 Mon Sep 17 00:00:00 2001 From: rodude123 Date: Sat, 3 Dec 2022 12:57:42 +0000 Subject: [PATCH] Added in ability to change password and fisxed some other smaller issues Signed-off-by: rodude123 --- .../changePassword.html | 28 +++++++++++++++++ .../changePassword.php | 25 ++++++++++++++++ .../css/changePassword.css | 18 +++++++++++ .../css/template.css | 2 +- .../index.html | 4 +-- .../isLoggedIn.php | 2 +- .../js/changePassword.js | 30 +++++++++++++++++++ .../login.php | 2 +- .../search.html | 2 +- .../search.php | 2 +- 10 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.php create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css create mode 100644 DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/changePassword.js diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html index 1604cbc..6bf547d 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.html @@ -3,8 +3,36 @@ Change Password + + +
+
+
+ + +
+
+ + +
+ +
+
+ + \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.php new file mode 100644 index 0000000..bc41a76 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/changePassword.php @@ -0,0 +1,25 @@ +prepare("UPDATE Users SET Users_password = :pass WHERE Users_username = :username"); + $stmt->bindParam(":pass", $pass); + $stmt->bindParam(":username", $_SESSION["username"]); + if ($stmt->execute()) + { + echo json_encode(array("message" => "ok")); + } + else + { + echo json_encode(array("message" => "Error updating password")); + } +} +else +{ + echo json_encode(array("message" => "Not logged in")); +} diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css new file mode 100644 index 0000000..71d7b35 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/changePassword.css @@ -0,0 +1,18 @@ +@import "nav.css"; + +main { + padding-top: 2.5em; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +main form { + width: 15%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: flex-start; + gap: 1em; +} diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css index a33e69b..cb20796 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/css/template.css @@ -46,7 +46,7 @@ h1, h2 { } .btnPrimary:hover { - background-color: var(--primary); + background-color: var(--hover); } div.formControl { diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html index 79b7f3d..614f1ae 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/index.html @@ -15,11 +15,11 @@
- +
- +
diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php index 63ae5e8..6b73ca8 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/isLoggedIn.php @@ -1,6 +1,6 @@ "ok")); diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/changePassword.js b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/changePassword.js new file mode 100644 index 0000000..a6090e8 --- /dev/null +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/changePassword.js @@ -0,0 +1,30 @@ +// Change Password stuff + +document.querySelector("#changePass").addEventListener("submit", e => +{ + e.preventDefault(); + let formData = new FormData(); + if (document.querySelector("#pass").value !== document.querySelector("#rePass").value) + { + alert("Passwords do not match"); + } + else + { + formData.append("password", document.querySelector("#rePass").value); + fetch("changePassword.php", { + method: "POST", + body: formData + }).then(res => res.json().then(json => + { + if (json.message === "ok") + { + alert("Password changed successfully"); + } + else + { + alert(json.message); + } + })); + } + +}); \ No newline at end of file diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php index 5c44d7c..02c1cda 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/login.php @@ -1,7 +1,7 @@ Create new user
  • Add Fines
  • View log
  • -
  • Change password
  • +
  • Change password
  • Logout
  • diff --git a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.php b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.php index 8b00f44..df7c65e 100644 --- a/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.php +++ b/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/search.php @@ -1,7 +1,7 @@