initialize user
This commit is contained in:
parent
baa5105be5
commit
166ac751c8
@ -6,6 +6,7 @@ require_once "lib/navigation.php";
|
||||
require_once "lib/router.php";
|
||||
require_once "lib/page.php";
|
||||
require_once "lib/endpoint.php";
|
||||
require_once "lib/account.php";
|
||||
|
||||
$routerConfig = array();
|
||||
$routerRequest = array();
|
||||
@ -15,6 +16,11 @@ if(initRouter()) {
|
||||
/** @noinspection PhpArrayIsAlwaysEmptyInspection */
|
||||
session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true);
|
||||
session_start();
|
||||
|
||||
if(!isLoggedIn()){
|
||||
setDefaultSessionData();
|
||||
}
|
||||
|
||||
if($routerRequest["type"] == "api") {
|
||||
echo getEndpoint($routerRequest["page_name"]);
|
||||
|
||||
|
@ -8,6 +8,17 @@ function isLoggedIn(): bool
|
||||
return $_SESSION["ID"] > 0 && !empty($_SESSION["email"]) && $_SESSION["privilegelevel"] >= $routerConfig["logged_in_default_permission_level"];
|
||||
}
|
||||
|
||||
function setDefaultSessionData(): void
|
||||
{
|
||||
$_SESSION["ID"] = 0;
|
||||
$_SESSION["first_name"] = "";
|
||||
$_SESSION["last_name"] = "";
|
||||
$_SESSION["nickname"] = "";
|
||||
$_SESSION["email"] = "";
|
||||
$_SESSION["mcnick"] = "";
|
||||
$_SESSION["privilegelevel"] = 0;
|
||||
}
|
||||
|
||||
function generateActivationToken(): string
|
||||
{
|
||||
try {
|
||||
|
13
lib/page.php
13
lib/page.php
@ -73,7 +73,10 @@ function getPage($page_name = null): array|false|string
|
||||
$page = $pageMetadata["output"];
|
||||
}
|
||||
else{
|
||||
$page = file_get_contents($routerConfig["template_dir"] . "404.html");
|
||||
$page_tmp = file_get_contents($routerConfig["template_dir"] . "404.html");
|
||||
$pageMetadata = parsePageTag($page_tmp);
|
||||
$page = $pageMetadata["output"];
|
||||
http_response_code(404);
|
||||
}
|
||||
|
||||
print_r($pageMetadata["parameters"]);
|
||||
@ -96,11 +99,15 @@ function getPage($page_name = null): array|false|string
|
||||
|
||||
if($page_required_permission < $_SESSION["privilegelevel"]){
|
||||
if($is_secret_page == 1) {
|
||||
$page = file_get_contents($routerConfig["template_dir"] . "404.html"); //fake 404 error
|
||||
$page_tmp = file_get_contents($routerConfig["template_dir"] . "404.html");
|
||||
$pageMetadata = parsePageTag($page_tmp);
|
||||
$page = $pageMetadata["output"];
|
||||
http_response_code(404);
|
||||
}
|
||||
else{
|
||||
$page = file_get_contents($routerConfig["template_dir"] . "403.html"); //deny access if doesnt have permissions
|
||||
$page_tmp = file_get_contents($routerConfig["template_dir"] . "403.html");
|
||||
$pageMetadata = parsePageTag($page_tmp);
|
||||
$page = $pageMetadata["output"];
|
||||
http_response_code(403);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user