Site layout changes and more flexbox experiements with CSS.
This commit is contained in:
154
admin/auth.php
154
admin/auth.php
@ -1,91 +1,91 @@
|
||||
<!-- login system -->
|
||||
<!-- Login system -->
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Check if user has admin accesss
|
||||
function auth()
|
||||
{
|
||||
if($_SESSION["login"] != "admin")
|
||||
{
|
||||
header("location:../admin/login.php");
|
||||
}
|
||||
// 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";
|
||||
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;
|
||||
$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;
|
||||
}
|
||||
|
||||
// Logins in to index.php
|
||||
// checks username and password for a match in users
|
||||
function login()
|
||||
{
|
||||
$connection = connect();
|
||||
// Logs in to index.php and checks username and password for a match in users
|
||||
function login_post() {
|
||||
$connection = connect();
|
||||
|
||||
// login if input found
|
||||
if(isset($_POST["username"]) and isset($_POST["password"]))
|
||||
{
|
||||
$username = $_POST["username"];
|
||||
$password = $_POST["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 = '$password'";
|
||||
|
||||
$result = pg_query($connection, $sql);
|
||||
if (!result)
|
||||
{
|
||||
die("pg_query error: " . pg_last_error($db));
|
||||
}
|
||||
$rowCount = pg_num_rows($result);
|
||||
|
||||
// if any user matches login attempt
|
||||
if ($rowCount == 1)
|
||||
{
|
||||
session_start();
|
||||
$_SESSION["login"] = "admin";
|
||||
header("location:index.php");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Invalid username or password. Failed to login.";
|
||||
}
|
||||
}
|
||||
// Attempt login
|
||||
if(isset($_POST["username"]) and isset($_POST["password"])) {
|
||||
$username = $_POST["username"];
|
||||
$password = $_POST["password"];
|
||||
login($username, $password);
|
||||
}
|
||||
}
|
||||
|
||||
function add_user()
|
||||
{
|
||||
if (isset($_POST["username"]) and isset($_POST["password"]))
|
||||
{
|
||||
// include_once("../includes/connect.php");
|
||||
$connection = connect();
|
||||
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);
|
||||
|
||||
// encrypt password and add new user
|
||||
$username = $_POST["username"];
|
||||
$password = $_POST["password"];
|
||||
$salt = "salt";
|
||||
$password = md5($salt.$password.$salt);
|
||||
$query= "INSERT INTO t_users(UID, UNAME, PWORD) VALUES(NULL, '$username', '$password')";
|
||||
$run = pg_query($connect, $query) or pg_last_error($connection);
|
||||
// Search for matching username and password
|
||||
$sql = "SELECT * FROM users WHERE name = '$username' AND password = '$newPassword'";
|
||||
|
||||
// return to users page
|
||||
header("Location:users.php");
|
||||
}
|
||||
$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");
|
||||
}
|
||||
}?>
|
||||
|
@ -1,24 +1,78 @@
|
||||
<?php require_once("./auth.php"); auth(); ?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<title>Quartznet | Admin</title>
|
||||
|
||||
<head>
|
||||
<title>Quartznet | Admin</title>
|
||||
|
||||
<?php include "../includes/head.php" ?>
|
||||
<?php include "../includes/header.php" ?>
|
||||
</head>
|
||||
|
||||
<main class="container">
|
||||
<section>
|
||||
<h1>Admin area</h1>
|
||||
<a class="link" href="/quartznet/admin/logout.php">Logout</a>
|
||||
<br>
|
||||
<a class="link" href="/quartznet/admin/users.php">Users</a>
|
||||
<br>
|
||||
<p>For admins of quartznet. Ignore the fire. Everything is fine now! :) </p>
|
||||
<img src="../assets/friendscats1.png" alt="cats">
|
||||
</section>
|
||||
</main>
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<nav>
|
||||
<a class="title" href="/quartznet/">Quartznet</a>
|
||||
<ul class="menu">
|
||||
<li><a href="/quartznet/about">About</a></li>
|
||||
<li><a href="/quartznet/contact">Contact</a></li>
|
||||
<li><a href="/quartznet/admin">Admin</a></li>
|
||||
|
||||
<li><a class="link" href="https://quartznet.info/sound">Sound</a></li>
|
||||
<li><a class="link" href="https://quartznet.info/status">Status</a></li>
|
||||
<li><a class="link" href="https://quartznet.info/git">Git</a></li>
|
||||
<li><a class="link" href="https://quartznet.info/sql">SQL</a></li>
|
||||
<li><a class="link" href="/quartznet/admin/logout.php">Logout</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</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>
|
||||
|
||||
<?php include "../includes/footer.php" ?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php require_once("./auth.php"); login(); ?>
|
||||
|
||||
<!-- Quartznet login page -->
|
||||
<?php
|
||||
require_once("./auth.php");
|
||||
login_post();
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@ -9,35 +10,35 @@
|
||||
<?php include "../includes/head.php" ?>
|
||||
<?php include "../includes/header.php" ?>
|
||||
|
||||
<main class="container">
|
||||
<section>
|
||||
<main>
|
||||
<section class="container">
|
||||
|
||||
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
|
||||
|
||||
<h5 class="card-title text-center">Log in</h5>
|
||||
<form class="form-signin" action="login.php" method="post">
|
||||
<div class="form-label-group">
|
||||
<input type="text" id="username" class="form-control" name="username" placeholder="Username" required autofocus>
|
||||
<label for="username">Username</label>
|
||||
</div>
|
||||
<h2 class="card-title">Login</h2>
|
||||
<form class="form-signin" action="login.php" method="post">
|
||||
<div class="form-label-group">
|
||||
<input type="text" id="username" class="form-control" name="username" placeholder="Username" required autofocus>
|
||||
<label for="username">Username</label>
|
||||
</div>
|
||||
|
||||
<div class="form-label-group">
|
||||
<input type="password" id="password" class="form-control" name="password" placeholder="Password" required>
|
||||
<label for="inputPassword">Password</label>
|
||||
</div>
|
||||
<div class="form-label-group">
|
||||
<input type="password" id="password" class="form-control" name="password" placeholder="Password" required>
|
||||
<label for="inputPassword">Password</label>
|
||||
</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>
|
||||
|
||||
<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>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<?php include "../includes/footer.php" ?>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
@ -45,7 +45,6 @@ $rows = pg_num_rows($result);
|
||||
</table>
|
||||
|
||||
<!--Insert new user-->
|
||||
<br>
|
||||
<form method="post" action="users.php" name="login">
|
||||
<div class="form-group">
|
||||
<input name="username" type="text" required placeholder="username" maxlength="30">
|
||||
|
Reference in New Issue
Block a user