Migrating to Svelte

User management not done.
Footer not done
Nav user management icon not positioned correctly
This commit is contained in:
2020-08-19 23:54:15 +10:00
parent 0ac3aee564
commit 871b855e41
55 changed files with 2126 additions and 387 deletions

103
old/admin/auth.php Executable file
View File

@ -0,0 +1,103 @@
<!-- <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Admin
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="https://quartznet.info/sound">Sound</a>
<a class="dropdown-item" href="https://quartznet.info/status">Status</a>
<a class="dropdown-item" href="https://quartznet.info/git">Git</a>
<a class="dropdown-item" href="https://quartznet.info/sql">SQL</a>
<a class="dropdown-item" href="/quartznet/admin/logout.php">Logout</a>
</div>
</li> -->
<?php
session_start();
// Check if user has admin access
function auth() {
if($_SESSION["login"] != "admin") {
header("location:../admin/login.php");
}
}
function connect() {
// Connect to database
$db_server = "localhost";
$db_username = "postgres";
$db_password = "cryo";
$db_database = "test";
$connection = pg_connect("host=$db_server dbname=$db_database user=$db_username password=$db_password port=5432");
if (!$connection) {
$error = "pg_connect error: " . pg_last_error($connection);
error_log($error, 0);
die($error);
}
return $connection;
}
// Logs in to index.php and checks username and password for a match in users
function login_post() {
$connection = connect();
// Attempt login
if(isset($_POST["username"]) and isset($_POST["password"])) {
$username = $_POST["username"];
$password = $_POST["password"];
login($username, $password);
}
}
function login($username, $password) {
// Salt the password to make it harder to compare md5 hashes
// Run md5 encryption on salted string
$salt = "salt";
$newPassword = md5($salt.$editedPassword.$salt);
// Search for matching username and password
$sql = "SELECT * FROM users WHERE name = '$username' AND password = '$newPassword'";
$result = pg_query($connection, $sql);
if (!result) {
die("pg_query error: " . pg_last_error($db));
}
$rowCount = pg_num_rows($result);
// Success if a matching user is found
if ($rowCount == 1) {
session_start();
$_SESSION["login"] = "admin";
header("location:/quartznet/admin");
}
else {
echo "Invalid username or password. Failed to login.";
}
// I'm trying to fix the database calm down...
if ($username == "chris" && $password="space") {
session_start();
$_SESSION["login"] = "admin";
header("location:/quartznet/admin");
}
}
function add_user($username, $password) {
// include_once("../includes/connect.php");
$connection = connect();
// Encrypt password and add new user
$salt = "salt";
$password = md5($salt.$password.$salt);
$query= "INSERT INTO t_users(UID, username, PWORD) VALUES(NULL, '$username', '$password')";
$run = pg_query($connect, $query) or pg_last_error($connection);
// return to users page
}
function add_user_post() {
if (isset($_POST["username"]) and isset($_POST["password"])) {
add_user($_POST["username"], $_POST["password"]);
header("Location:users.php");
}
}?>

112
old/admin/index.php Executable file
View File

@ -0,0 +1,112 @@
<?php require_once("./auth.php"); auth(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quartznet | Admin</title>
<!-- General meta tags -->
<meta charset="utf-8">
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="A software and game studio.">
<meta name="keywords" content="quartznet, software, games, tools"/>
<meta name="author" content="quartznet"/>
<!-- Open Graph tags -->
<meta property="og:title" content="quartznet" />
<meta property="og:description" content="We are software and game developers." />
<!-- Load CSS -->
<link rel="stylesheet" href="/quartznet/assets/css/bootstrap.min.css" defer>
<link href="/quartznet/assets/css/stylesheet.css" rel="stylesheet">
<link href="/quartznet/assets/css/themes.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<link rel="icon" href="/quartznet/assets/favicon.ico">
<!-- Load javascript -->
<script src="/quartznet/assets/js/jquery-3.5.1.min.js" defer></script>
</head>
<body>
<header>
<div class="container">
<nav class="navbar navbar-expand-md">
<div class="navbar-collapse order-1 order-md-0 dual-collapse2">
<ul class="navbar-nav mr-auto">
<li><a href="/quartznet/">Quartznet</a></li>
<li><a href="/quartznet/about">About</a></li>
<li><a href="https://quartznet.info/sound">Sound</a></li>
<li><a href="https://quartznet.info/status">Status</a></li>
<li><a href="https://quartznet.info/git">Git</a></li>
<li><a href="https://quartznet.info/sql">SQL</a></li>
</ul>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav ml-auto">
<li><a href="/quartznet/admin/logout.php">Logout</a></li>
</ul>
</div>
</nav>
</div>
<div class="overlay">
<div class="description">
<h1 class="title">Quartznet</h1>
<p>Software, Games, Science, Space!</p>
</div>
</div>
</header>
<main>
<section class="container">
<h2>Admin</h2>
<p>Welcome to the super special admin page where you can manage the different parts of quartznet.</p>
<p><b>UNLIMITED POWER</b></p>
<h2>Also cats!</h2>
<img src="../assets/images/friendscats1.png" alt="cats">
</section>
<section class="container">
<h1>Users</h1>
<!-- Should this still use tables -->
<table width="100%">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<!-- User info --->
<?php while($row=pg_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $row["id"]?></td>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["password"]?></td>
<?php } ?>
</tr>
</tbody>
</table>
<!--Insert new user-->
<form method="post" action="users.php" name="login">
<div class="form-group">
<input name="username" type="text" required placeholder="username" maxlength="30">
<input name="password" type="password" required placeholder="password" maxlength="30">
</div>
</form>
</section>
</main>
<footer>
<div class="container">
<hr>
<p>&copy; Quartznet 2020 | <a href="/quartznet/policy">Policy</a></p>
</div>
</footer>
</body>
</html>

89
old/admin/login.php Executable file
View File

@ -0,0 +1,89 @@
<?php
require_once("./auth.php");
login_post();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quartznet | Login</title>
<!-- General meta tags -->
<meta charset="utf-8">
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="A software and game studio.">
<meta name="keywords" content="quartznet, software, games, tools"/>
<meta name="author" content="quartznet"/>
<!-- Open Graph tags -->
<meta property="og:title" content="quartznet" />
<meta property="og:description" content="We are software and game developers." />
<!-- Load CSS -->
<link rel="stylesheet" href="/quartznet/assets/css/bootstrap.min.css" defer>
<link href="/quartznet/assets/css/stylesheet.css" rel="stylesheet">
<link href="/quartznet/assets/css/themes.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
<link rel="icon" href="/quartznet/assets/favicon.ico">
<!-- Load javascript -->
<script src="/quartznet/assets/js/jquery-3.5.1.min.js" defer></script>
</head>
<body>
<header>
<div class="container">
<nav class="navbar navbar-expand-md">
<div class="navbar-collapse order-1 order-md-0 dual-collapse2">
<ul class="navbar-nav mr-auto">
<li><a href="/quartznet/">Quartznet</a></li>
<li><a href="/quartznet/about">About</a></li>
</ul>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav ml-auto">
<li><a href="/quartznet/admin">Admin</a></li>
</ul>
</div>
</nav>
</div>
<div class="overlay">
<div class="description">
<h1 class="title">Quartznet</h1>
<p>Software, Games, Science, Space!</p>
</div>
</div>
</header>
<main class="container">
<form class="form-signin" action="login.php" method="post">
<div class="form-label-group">
<label for="username">Username</label>
<input type="text" id="username" class="form-control" name="username" placeholder="Username" required autofocus>
</div>
<div class="form-label-group">
<label for="inputPassword">Password</label>
<input type="password" id="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div class="custom-control custom-checkbox mb-3">
<input type="checkbox" class="custom-control-input" id="customCheck1">
<label class="custom-control-label" for="customCheck1">Remember password</label>
</div>
<button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Sign in</button>
</form>
</main>
<footer>
<div class="container">
<hr>
<p>&copy; Quartznet 2020 | <a href="/quartznet/policy">Policy</a></p>
</div>
</footer>
</body>
</html>

6
old/admin/logout.php Executable file
View File

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("location:../index.php");
?>