added custom session manager, moved index to safe directory
parent
b1cc12673c
commit
0ea15ae4b2
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
use function _\find;
|
||||||
|
use ReallySimpleJWT\Token;
|
||||||
|
|
||||||
|
class Session
|
||||||
|
{
|
||||||
|
private static $file = "../content/.session";
|
||||||
|
private static $data = [
|
||||||
|
"member" => "",
|
||||||
|
"token" => "",
|
||||||
|
];
|
||||||
|
public static function start()
|
||||||
|
{
|
||||||
|
if (!is_file(self::$file)) {
|
||||||
|
file_put_contents(self::$file, json_encode(self::$data));
|
||||||
|
} else {
|
||||||
|
($new = fopen(self::$file, "w")) or die("Unable to open file!");
|
||||||
|
fwrite($new, json_encode(self::$data));
|
||||||
|
fclose($new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function active()
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
if ($data["member"] != null) {
|
||||||
|
$secret = (new Settings())->getFolks("secret");
|
||||||
|
if (
|
||||||
|
Token::validate($data["token"], $secret) &&
|
||||||
|
Token::validateExpiration($data["token"], $secret)
|
||||||
|
) {
|
||||||
|
true;
|
||||||
|
} else {
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function set($key, $value)
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
$data[$key] = $value;
|
||||||
|
($fresh = fopen(self::$file, "w")) or die("Unable to open file!");
|
||||||
|
fwrite($fresh, json_encode($data));
|
||||||
|
fclose($fresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get($key)
|
||||||
|
{
|
||||||
|
$data = json_decode(file_get_contents(self::$file), true);
|
||||||
|
|
||||||
|
return $data[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function kill()
|
||||||
|
{
|
||||||
|
($fresh = fopen(self::$file, "w")) or die("Unable to open file!");
|
||||||
|
fwrite($fresh, json_encode(self::$data));
|
||||||
|
fclose($fresh);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
//include "brain/data/Auth.inc.php";
|
||||||
|
|
||||||
|
class StringTools
|
||||||
|
{
|
||||||
|
public static function randomString(int $length)
|
||||||
|
{
|
||||||
|
$alphanum =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
$special = '*&!@%^#$';
|
||||||
|
$alphabet = $alphanum . $special;
|
||||||
|
$random = openssl_random_pseudo_bytes($length);
|
||||||
|
$alphabet_length = strlen($alphabet);
|
||||||
|
$string = "";
|
||||||
|
for ($i = 0; $i < $length; ++$i) {
|
||||||
|
$string .= $alphabet[ord($random[$i]) % $alphabet_length];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,15 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"handle": "ItsRo",
|
"handle": "ItsRo",
|
||||||
"avi": "/assets/images/user/2020/09/download20200802144459.png",
|
"avi": "/assets/images/user/2020/09/download20200802144459.png",
|
||||||
"email": "are0h@protonmail.com",
|
"email": "are0h@protonmail.com",
|
||||||
"password": "$2b$10$77PMC2W6aZ3gJP7TOA7OpeqQaz..SrRSO74WEa7cn61ehHI55.zKq",
|
"password": "$2b$10$77PMC2W6aZ3gJP7TOA7OpeqQaz..SrRSO74WEa7cn61ehHI55.zKq",
|
||||||
"key": "fe79df250470815bf32dcea70221384c89163cad3a827a9c3da25d87159ed55a",
|
"key": "fe79df250470815bf32dcea70221384c89163cad3a827a9c3da25d87159ed55a",
|
||||||
"role": "hnic",
|
"secret": "&eIWQ8E&@vh*",
|
||||||
"created": "2020-09-01T22:46:47+02:00",
|
"role": "hnic",
|
||||||
"updated": "2020-09-01T22:46:47+02:00",
|
"created": "2020-09-01T22:46:47+02:00",
|
||||||
"deleted": null
|
"updated": "2020-09-01T22:46:47+02:00",
|
||||||
}
|
"deleted": null
|
||||||
|
}
|
||||||
]
|
]
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
require __DIR__ . "/vendor/autoload.php";
|
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
||||||
use Slim\Factory\AppFactory;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use Slim\Views\TwigMiddleware;
|
|
||||||
|
|
||||||
include "brain/controller/RouteControl.inc.php";
|
|
||||||
include "brain/data/Auth.inc.php";
|
|
||||||
|
|
||||||
$app = AppFactory::create();
|
|
||||||
$twig = Twig::create("brain/views/");
|
|
||||||
$app->add(TwigMiddleware::create($app, $twig));
|
|
||||||
session_start();
|
|
||||||
//set up routing
|
|
||||||
$app->get("/[{first}[/{second}[/{third}[/{fourth}]]]]", "\RouteControl:get");
|
|
||||||
$app->post("/[{first}[/{second}[/{third}[/{fourt}]]]]", "\RouteControl:post");
|
|
||||||
//start the app
|
|
||||||
$app->run();
|
|
Loading…
Reference in New Issue