diff --git a/backend/changepass.php b/backend/changepass.php new file mode 100644 index 0000000..49bc4e5 --- /dev/null +++ b/backend/changepass.php @@ -0,0 +1,43 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +if ($_SERVER["REQUEST_METHOD"] == "POST") { // When user posts data + $currentpass = $_POST["currentpass"]; + $newpass = $_POST["newpass"]; + $repeat = $_POST["repeatnewpass"]; + + $user_row = $conn->query("SELECT * FROM users WHERE username = '$username';")->fetch_assoc(); + + if($currentpass != $user_row["password"]) { + header("Location: /settings.php?wrongold"); + exit; + } + + if($newpass != $repeat) { + header("Location: /settings.php?wrongrepeat"); + exit; + } + + $result = $conn->query("UPDATE users SET password = '$newpass' WHERE username = '$username';"); + + if(!$result) { + die("Error changing password"); + } + + header("Location: /settings.php?changed"); + $conn->close(); + exit; +} +?> + diff --git a/backend/logout.php b/backend/logout.php index f61e651..598ae48 100644 --- a/backend/logout.php +++ b/backend/logout.php @@ -2,6 +2,7 @@ session_start(); session_destroy(); header("Location: /"); +if(isset($_GET["deleted"])) { header("Location: /?deleted"); } exit; ?> diff --git a/backend/userdel.php b/backend/userdel.php new file mode 100644 index 0000000..9ed0673 --- /dev/null +++ b/backend/userdel.php @@ -0,0 +1,47 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +if ($_SERVER["REQUEST_METHOD"] == "POST") { // When user posts data + $password = $_POST["password"]; + + $user_row = $conn->query("SELECT * FROM users WHERE username = '$username';")->fetch_assoc(); + + $password_confirm = $user_row["password"]; + + if($password != $password_confirm) { + header("Location: /settings.php?wrongpass"); + $conn->close(); + exit; + } + + $user_id = $user_row["id"]; + + $result = $conn->query("DROP TABLE user$user_id;"); + + if(!$result) { + die("Error removing data."); + } + + $result = $conn->query("DELETE FROM users WHERE username = '$username';"); + + if(!$result) { + die("Error deleting user."); + } + + header("Location: logout.php?deleted"); + $conn->close(); + exit; +} +?> + diff --git a/dashboard.php b/dashboard.php index 09ff6d6..061d25b 100644 --- a/dashboard.php +++ b/dashboard.php @@ -32,6 +32,7 @@ $table = $conn->query("SELECT * FROM user" . $user_id . " ORDER BY name;");
+ +
++ +
+Warning: You cannot recover your account after it has been deleted!
+ ++ +
+ + + + +close(); ?> diff --git a/style.css b/style.css index 03d92c9..2d40067 100644 --- a/style.css +++ b/style.css @@ -49,6 +49,16 @@ header { text-align: left; } +.settings-link { + float: right; + font-size: 175%; + text-decoration: none; + min-height: 3rem; + display: flex; + padding: 0 .5rem; + align-items: center; +} + .error { color: var(--red); } @@ -136,6 +146,7 @@ input[type=text], input[type=password], input[type=submit], input[type=number], +input[type=button], .btn { background: rgba(0, 0, 0, 0.5); border: thin solid var(--darker); @@ -149,10 +160,12 @@ input[type=number], } input[type=number] { - padding: .5rem 1.5rem; + padding: .5rem 1rem; + width: 13ch; } input[type=submit]:hover, +input[type=button]:hover, input[type=text]:hover, input[type=text]:focus, input[type=password]:hover, @@ -178,8 +191,3 @@ input[type=submit]:active, padding: 0 !important; } -input[type=number] { - width: 10ch; -} - -