Added in ability to change password and fisxed some other smaller issues #3

Merged
rodude123 merged 1 commits from change-password into master 2022-12-03 12:58:58 +00:00
10 changed files with 108 additions and 7 deletions

View File

@ -3,8 +3,36 @@
<head>
<meta charset="UTF-8">
<title>Change Password</title>
<link rel="stylesheet" href="css/changePassword.css">
</head>
<body>
<nav>
<ul>
<li><a href="search.html" class="btn">Search</a></li>
<li><a href="newVehicle.html" class="btn">Add new vehicle</a></li>
<li><a href="newReport.html" class="btn">Create new report</a></li>
<li><a href="newUser.html" class="btn">Create new user</a></li>
<li><a href="addFines.html" class="btn">Add Fines</a></li>
<li><a href="viewLog.html" class="btn">View log</a></li>
<li><a href="changePassword.html" class="btn active">Change password</a></li>
<li><a href="#" class="btn">Logout</a></li>
</ul>
</nav>
<main>
<form action="" method="POST" id="changePass">
<div class="formControl">
<label for="pass">Password</label>
<input type="password" name="pass" id="pass">
</div>
<div class="formControl">
<label for="rePass">Retype Password</label>
<input type="password" name="rePass" id="rePass">
</div>
<input type="submit" value="Change Password" class="btn btnPrimary">
</form>
</main>
<script src="js/changePassword.js"></script>
</body>
</html>

View File

@ -0,0 +1,25 @@
<?php
session_start();
require_once 'config.php';
header('Content-Type: application/json');
if (isset($_SESSION["username"]))
{
$pass = $_POST["password"];
$conn = dbConn();
$stmt = $conn->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"));
}

View File

@ -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;
}

View File

@ -46,7 +46,7 @@ h1, h2 {
}
.btnPrimary:hover {
background-color: var(--primary);
background-color: var(--hover);
}
div.formControl {

View File

@ -15,11 +15,11 @@
<form method="POST" class="loginForm" id="login">
<div class="formControl">
<label for="username">Username</label>
<input type="text" name="username" id="username">
<input type="text" name="username" id="username" required>
</div>
<div class="formControl">
<label for="password">Password</label>
<input type="password" name="password" id="password">
<input type="password" name="password" id="password" required>
</div>
<input type="submit" value="Login" class="btn btnPrimary">
</form>

View File

@ -1,6 +1,6 @@
<?php
session_start();
header('Content-Type: application/json');
if (isset($_SESSION["username"]))
{
echo json_encode(array("message" => "ok"));

View File

@ -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);
}
}));
}
});

View File

@ -1,7 +1,7 @@
<?php
session_start();
require_once 'config.php';
header('Content-Type: application/json');
$username = $_POST["username"];
$password = $_POST["password"];

View File

@ -15,7 +15,7 @@
<li><a href="newUser.html" class="btn">Create new user</a></li>
<li><a href="addFines.html" class="btn">Add Fines</a></li>
<li><a href="viewLog.html" class="btn">View log</a></li>
<li><a href="changePassword.html">Change password</a></li>
<li><a href="changePassword.html" class="btn">Change password</a></li>
<li><a href="#" class="btn">Logout</a></li>
</ul>
</nav>

View File

@ -1,7 +1,7 @@
<?php
session_start();
require_once 'config.php';
header('Content-Type: application/json');
if (isset($_SESSION["username"]))
{
$searchType = $_POST["searchType"];