cinetrack/settings.php

85 lines
20 KiB
PHP
Raw Permalink Normal View History

2023-07-10 16:20:06 +02:00
<?php
session_start();
if (!isset($_SESSION["username"])) {
header("Location: /"); // Redirect to the login page if not logged in
exit;
}
$username = $_SESSION["username"];
$env = parse_ini_file("config/.env");
// Connect to db
$conn = new mysqli($env["HOST"], $env["DBUSER"], $env["DBPASS"], $env["TABLE"]);
if($conn->connect_error) {
die("Database connection failed: " . $conn->connect_error);
}
$user_id = $conn->query("SELECT * FROM users WHERE username = '$username'")->fetch_assoc()["id"];
$table = $conn->query("SELECT * FROM user" . $user_id . " ORDER BY name;");
?>
<!DOCTYPE html>
<html>
<head>
<title>Dashboard - CineTrack</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/style.css" />
<link rel="icon" type="image/x-icon" href="/favico.ico">
</head>
<body>
<header>
<svg width="332.414" height="45.704" viewBox="0 0 332.414 45.704" xmlns="http://www.w3.org/2000/svg"><g id="svgGroup" stroke-linecap="round" fill-rule="evenodd" font-size="9pt" stroke="#eeeeee" stroke-width="0.25mm" fill="#eeeeee" style="stroke:#eeeeee;stroke-width:0.25mm;fill:#eeeeee"><path d="M 116.543 30.139 L 116.543 34.735 L 134.037 34.735 L 134.037 36.563 L 116.543 36.563 L 116.543 38.391 L 134.037 38.391 L 134.037 40.219 L 116.543 40.219 L 116.543 42.047 L 134.037 42.047 L 134.037 43.876 L 114.715 43.876 L 114.715 7.313 L 134.037 7.313 L 134.037 9.141 L 116.543 9.141 L 116.543 10.969 L 134.037 10.969 L 134.037 12.797 L 116.543 12.797 L 116.543 14.626 L 134.037 14.626 L 134.037 16.454 L 116.543 16.454 L 116.543 20.999 L 133.022 20.999 L 133.022 22.827 L 116.543 22.827 L 116.543 24.655 L 133.022 24.655 L 133.022 26.483 L 116.543 26.483 L 116.543 28.311 L 133.022 28.311 L 133.022 30.139 L 116.543 30.139 Z M 144.93 10.969 L 137.617 10.969 L 137.617 9.141 L 165.039 9.141 L 165.039 10.969 L 157.727 10.969 L 157.727 43.876 L 155.899 43.876 L 155.899 10.969 L 154.07 10.969 L 154.07 43.876 L 152.242 43.876 L 152.242 10.969 L 150.414 10.969 L 150.414 43.876 L 148.586 43.876 L 148.586 10.969 L 146.758 10.969 L 146.758 43.876 L 144.93 43.876 L 144.93 10.969 Z M 182.99 35.547 L 182.99 33.719 L 194.01 33.719 Q 197.387 33.719 200.256 32.094 A 12.292 12.292 0 0 0 204.839 27.575 A 12.325 12.325 0 0 0 206.553 21.176 A 11.212 11.212 0 0 0 204.852 15.222 A 12.587 12.587 0 0 0 200.243 10.792 Q 197.336 9.141 194.01 9.141 L 171.006 9.141 L 171.006 43.876 L 169.178 43.876 L 169.178 7.313 L 194.01 7.313 A 13.956 13.956 0 0 1 199.532 8.443 A 15.294 15.294 0 0 1 203.204 10.631 A 14.022 14.022 0 0 1 204.115 11.439 Q 206.045 13.305 207.213 15.87 Q 208.381 18.434 208.381 21.176 A 16.396 16.396 0 0 1 207.881 25.307 A 13.276 13.276 0 0 1 206.35 28.933 A 13.325 13.325 0 0 1 200.891 33.973 L 204.725 43.876 L 202.77 43.876 L 199.139 34.709 Q 198.453 34.938 197.539 35.167 L 200.967 43.876 L 199.012 43.876 L 195.66 35.471 A 16.591 16.591 0 0 1 194.437 35.543 A 18.931 18.931 0 0 1 194.01 35.547 L 197.234 43.876 L 195.305 43.876 L 192.106 35.547 L 190.455 35.547 L 193.527 43.876 L 191.598 43.876 L 188.5 35.547 L 182.99 35.547 Z M 251.164 25.848 L 251.164 43.876 L 249.336 43.876 L 249.336 25.848 Q 249.336 20.668 246.924 16.593 A 16.57 16.57 0 0 0 240.348 10.296 A 19.056 19.056 0 0 0 232.4 8.114 A 22.838 22.838 0 0 0 231.055 8.075 A 17.698 17.698 0 0 0 222.041 10.436 Q 217.953 12.797 215.617 16.822 A 17.169 17.169 0 0 0 213.281 25.594 A 17.48 17.48 0 0 0 214.284 31.523 A 16.759 16.759 0 0 0 216.011 35.045 A 14.805 14.805 0 0 0 217.026 36.423 A 18.774 18.774 0 0 0 221.038 40.042 A 18.052 18.052 0 0 0 225.939 42.352 A 18.532 18.532 0 0 0 231.283 43.139 A 14.404 14.404 0 0 0 236.971 41.997 L 236.971 43.876 Q 234.152 44.866 231.182 44.866 A 20.895 20.895 0 0 1 225.202 44.002 A 19.183 19.183 0 0 1 219.819 41.451 A 20.551 20.551 0 0 1 215.465 37.464 A 16.942 16.942 0 0 1 212.958 33.242 A 19.899 19.899 0 0 1 212.52 32.094 A 19.674 19.674 0 0 1 211.453 25.621 A 21.851 21.851 0 0 1 211.453 25.594 A 19.326 19.326 0 0 1 212.939 18.091 A 19.174 19.174 0 0 1 216.683 12.25 A 18.41 18.41 0 0 1 217.001 11.921 A 18.595 18.595 0 0 1 222.127 8.289 A 21.764 21.764 0 0 1 223.247 7.783 Q 226.916 6.247 231.055 6.247 A 22.164 22.164 0 0 1 238.013 7.326 A 20.873 20.873 0 0 1 238.977 7.668 A 19.9 19.9 0 0 1 243.966 10.423 A 18.217 18.217 0 0 1 245.375 11.617 A 17.604 17.604 0 0 1 249.197 16.895 A 20.643 20.643 0 0 1 249.615 17.825 A 20.048 20.048 0 0 1 251.126 24.507 A 23.517 23.517 0 0 1 251.164 25.848 Z M 41.742 10.004 L 40.219 10.995 Q 37.324 6.754 32.741 4.292 Q 28.158 1.829 22.852 1.829 A 20.588 20.588 0 0 0 14.689 3.492 A 21.368 21.368 0 0 0 8.88 7.121 A 20.08 20.08 0 0 0 7.973 7.973 A 20.942 20.942 0 0 0 3.704 14.206 A 23.883 23.883 0 0 0 3.491 14.689 A 20.588 20.588 0 0 0 1.828 22.852 A 20.588 20.588 0 0 0 3.491 31.015 A 21.368 21.368 0 0 0 7.12 36.824 A 20.08 20.08 0 0 0 7.973 37.731 A 20.942 20.942 0 0 0 14.206 42 A 23.883 23.883 0 0 0 14.689 42.212 A 20.588 20.88
<a href='settings.php' class='settings-link'>&#9881;</a>
</header>
<h1>Settings for <?php echo $username; ?></h1>
<a class='btn' href='/dashboard.php'>Go Back</a>
<a class='btn' href="/backend/logout.php">Logout</a>
<br>
<h2>Change Password</h2>
<form method='post' action='/backend/changepass.php'>
<input type='password' name='currentpass' placeholder='Current password' required><br>
<input type='password' name='newpass' placeholder='New password' minlength='5' required><br>
<input type='password' name='repeatnewpass' placeholder='Repeat new password' minlength='5' required><br>
<input type='submit' value='Change Password'>
</form>
<p class='error'>
<?php
if(isset($_GET["wrongold"])) { echo "Wrong password."; }
if(isset($_GET["wrongrepeat"])) { echo "Your password does not match."; }
?>
</p>
<p>
<?php if(isset($_GET["changed"])) { echo "Password changed."; } ?>
</p>
<br>
<h2>Delete account</h2>
<p class='error'>Warning: You cannot recover your account after it has been deleted!</p>
<form method='post' action='/backend/userdel.php' id='delete_form'>
<input type='password' name='password' placeholder='Password' required><br>
<input type='button' value='Delete' id='delete_btn'>
</form>
<p class='error'>
<?php
if(isset($_GET["wrongpass"])) { echo "Wrong password."; }
?>
</p>
<script>
const form = document.getElementById("delete_form");
const button = document.getElementById("delete_btn");
button.addEventListener("click", confirmDelete);
function confirmDelete() {
if(confirm("Are you sure you want to delete your account?\nThis cannot be undone!") == true) {
form.submit();
}
}
</script>
</body>
</html>
<?php $conn->close(); ?>