First commit

This commit is contained in:
sorenpeter 2023-09-15 17:00:25 +02:00
parent 9eda1fd85d
commit 52926bc441
7 changed files with 110 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

3
.htaccess Normal file
View file

@ -0,0 +1,3 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php

23
index.php Normal file
View file

@ -0,0 +1,23 @@
<?php
$request = $_SERVER['REQUEST_URI'];
$viewDir = '/views/';
switch ($request) {
case '':
case '/':
require __DIR__ . $viewDir . 'home.php';
break;
case '/login':
require __DIR__ . $viewDir . 'login.php';
break;
case '/timeline':
require __DIR__ . $viewDir . 'timeline.php';
break;
default:
http_response_code(404);
require __DIR__ . $viewDir . '404.php';
}

20
partials/session.php Normal file
View file

@ -0,0 +1,20 @@
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
if($pass=="æøå123")
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}

1
php_server.sh Normal file
View file

@ -0,0 +1 @@
php -S localhost:8000

29
views/home.php Normal file
View file

@ -0,0 +1,29 @@
<?php
require_once("partials/session.php"); // TODO: Move all to base.php
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="../style.css">
<title>index.html</title>
</head>
<body >
<?php
if($_SESSION['password']=="æøå123") // TODO: Replace by var from config.ini
{
?>
<h1>You are loggged in now</h1>
<form method="post" action="" id="logout_form">
<input type="submit" name="page_logout" value="LOGOUT" style="background-color: #000; color: #f00; font-family: monospace;">
</form>
<?php
} else {
?>
<h1><a href="/login">Log in</a></h1>
<?php } ?>
</body>
</html>

34
views/login.php Normal file
View file

@ -0,0 +1,34 @@
<?php
require_once("partials/session.php"); // TODO: Move all to base.php
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="../style.css">
<title>Log in</title>
</head>
<body >
<?php
if($_SESSION['password']=="æøå123") // TODO: Replace by var from config.ini
{
?>
<h1>You are loggged in now</h1>
<form method="post" action="" id="logout_form">
<input type="submit" name="page_logout" value="LOGOUT" style="background-color: #000; color: #f00; font-family: monospace;">
</form>
<?php
} else {
?>
<h1>Log in:</h1>
<form method="post" action="" id="login_form">
<input type="password" name="pass" placeholder="*******"><br>
<input type="submit" name="submit_pass" value="Login">
<p><font style="color:red;"><?php echo $error;?></font></p>
</form>
<?php } ?>
</body>
</html>