Compare commits
3 Commits
baa5105be5
...
efbb04ff0a
Author | SHA1 | Date | |
---|---|---|---|
efbb04ff0a | |||
76a0568ee2 | |||
166ac751c8 |
@@ -1,29 +0,0 @@
|
||||
function login() {
|
||||
const email = document.getElementById("email").value;
|
||||
const password = document.getElementById("password").value;
|
||||
|
||||
// Assuming you use fetch API to send data to the server
|
||||
fetch('https://home.adlerka.top/account', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
action: 'login',
|
||||
email: email,
|
||||
password: password
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
document.getElementById("statusMessage").innerText = "Login successful!";
|
||||
// Redirect or perform other actions after successful login
|
||||
} else {
|
||||
document.getElementById("statusMessage").innerText = "Login failed. Please check your credentials.";
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
29
assets/scripts/global/account.js
Normal file
29
assets/scripts/global/account.js
Normal file
@@ -0,0 +1,29 @@
|
||||
function login() {
|
||||
const email = document.getElementById("email").value;
|
||||
const password = document.getElementById("password").value;
|
||||
|
||||
// Assuming you use fetch API to send data to the server
|
||||
fetch('https://home.adlerka.top/account', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
action: 'login',
|
||||
email: email,
|
||||
password: password
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
document.getElementById("statusMessage").innerText = "Login successful!";
|
||||
// Redirect or perform other actions after successful login
|
||||
} else {
|
||||
document.getElementById("statusMessage").innerText = "Login failed. Please check your credentials.";
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
@@ -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,12 @@ if(initRouter()) {
|
||||
/** @noinspection PhpArrayIsAlwaysEmptyInspection */
|
||||
session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true);
|
||||
session_start();
|
||||
|
||||
print_r(isLoggedIn());
|
||||
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 {
|
||||
|
46
lib/page.php
46
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);
|
||||
}
|
||||
}
|
||||
@@ -112,12 +119,45 @@ function getPage($page_name = null): array|false|string
|
||||
$page_title = $page_name;
|
||||
}
|
||||
|
||||
$site_name = $routerRequest["subdomain"];
|
||||
|
||||
if(!empty($pageMetadata["parameters"]["page_style"])){
|
||||
$style_location = $pageMetadata["parameters"]["page_style"];
|
||||
}
|
||||
else{
|
||||
$style_location = "assets/styles/$site_name/$page_name.css";
|
||||
}
|
||||
|
||||
if(file_exists($style_location)) {
|
||||
$style_tag = $style_location;
|
||||
}
|
||||
else{
|
||||
$style_tag = "";
|
||||
}
|
||||
|
||||
if(!empty($pageMetadata["parameters"]["page_script"])){
|
||||
$script_location = $pageMetadata["parameters"]["page_script"];
|
||||
}
|
||||
else{
|
||||
$script_location = "assets/scripts/$site_name/$page_name.js";
|
||||
}
|
||||
|
||||
if(file_exists($style_location)) {
|
||||
$script_tag = $script_location;
|
||||
}
|
||||
else{
|
||||
$script_tag = "";
|
||||
}
|
||||
|
||||
|
||||
$navpages = generateNavigation();
|
||||
|
||||
$nav = str_replace("__NAV_PAGES__", $navpages, $nav);
|
||||
|
||||
$out = $skeleton;
|
||||
$out = str_replace("__TEMPLATE__NAV__", $nav, $out);
|
||||
$out = str_replace("__TEMPLATE_PAGE_STYLE_TAG__", $style_tag, $out);
|
||||
$out = str_replace("__TEMPLATE_PAGE_SCRIPT_TAG__", $script_tag, $out);
|
||||
$out = str_replace("__TEMPLATE__PAGE__", $page, $out);
|
||||
return str_replace("__TEMPLATE_PAGE_TITLE__", $page_title, $out);
|
||||
}
|
@@ -10,6 +10,4 @@
|
||||
<button type="button" onclick="login()">Login</button>
|
||||
</form>
|
||||
<p id="statusMessage"></p>
|
||||
</div>
|
||||
|
||||
<script src="assets/login-script.js"></script>
|
||||
</div>
|
@@ -6,6 +6,8 @@
|
||||
<script src="https://kit.fontawesome.com/e9016e1de1.js" crossorigin="anonymous"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/remixicon/4.0.1/remixicon.min.css" integrity="sha512-dTsohxprpcruDm4sjU92K0/Gf1nTKVVskNHLOGMqxmokBSkfOAyCzYSB6+5Z9UlDafFRpy5xLhvpkOImeFbX6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<link rel="stylesheet" href="/assets/style.css">
|
||||
__TEMPLATE_PAGE_STYLE_TAG__
|
||||
__TEMPLATE_PAGE_SCRIPT_TAG__
|
||||
<script async src="https://umami.brn.systems/script.js" data-website-id="95e93885-5c19-4cab-ba9b-2f746a316a2a"></script>
|
||||
<title>Adlerka __TEMPLATE_PAGE_TITLE__</title>
|
||||
</head>
|
||||
|
Reference in New Issue
Block a user