declare(strict_types=1);
use Firebase\JWT\JWT;
require_once 'settings.php';
require_once 'bbcode.php';try {
$token = JWT::decode($authHeader, $secretKey, ['HS512']);
if ($token->iss !== $serverName ||
$token->nbf > $now->getTimestamp() ||
$token->exp < $now->getTimestamp() ||
mb_strtolower($token->data->userName) === $b_u) {
exit;
}
} catch (Exception $e) {
$userIsGuest = true;
}if(!isset($_POST["name"]) || !isset($_POST["comment"]) || strlen($_POST['name']) > 25 || strlen($_POST['comment']) == 0 || strlen($_POST['comment']) > $m_c) {
exit;
}$name = htmlspecialchars($_POST["name"]);
$name = str_replace(["\n", "\r"], '', $name);$comment = htmlspecialchars($_POST["comment"]);
$comment = str_replace(["\n", "\r"], '', $comment);if($userIsGuest && empty($comment)) {
exit;
}$comment = preg_replace('~https://i\.imgur\.com(*SKIP)(*FAIL)|https?://' . $_SERVER['SERVER_NAME'] . '(*SKIP)(*FAIL)|https?://~s', '', $comment);
$comment = showBBcodes($comment);$shout = new \JamesMoss\Flywheel\Document([
'text' => $comment,
'createdAt' => time()
]);if(!$userIsGuest) {
$shout['name'] = $token->data->userName;
$shout['loggedIn'] = 'true';
}if ($r_a === '1' && $userIsGuest) {
echo 'Access Denied';
exit;
}$repoShouts->store($shout);
Авиация
Сообщений 101 страница 110 из 134
Поделиться1012023-03-24 01:46 pm
Поделиться1022023-03-24 02:06 pm
let clicked = false;
const myButton = document.getElementById('myButton');
myButton.addEventListener('click', function() {
clicked = true;
});
Поделиться1032023-03-24 02:10 pm
document.addEventListener('submit', function(event) {
if (event.target.name === 'chx-login' || event.target.name === 'sign') {
// Do something if either form is submitted
console.log('Form submitted!');
}
});
Поделиться1042023-03-24 02:14 pm
const loginForm = document.forms['chx-login'];
const signForm = document.forms['sign'];loginForm.addEventListener('submit', function(event) {
// Do something when the login form is submitted
});signForm.addEventListener('submit', function(event) {
// Do something when the sign form is submitted
});
Поделиться1052023-03-24 02:20 pm
function ajaxFormSubmitted() {
setRegForm(); // WHY IS IT HERE, IS IT CORRECT?
formButtonClick();
console.log("ajaxformsubmitted")
const forms = document.querySelectorAll(".chx-login-form form");
forms.forEach(form => {
form.onsubmit = function(e) {
const xhr = new XMLHttpRequest();
xhr.open("POST", `${chatx_server}client/auth.php`, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
store.setJWT(data.jwt); // TEST
makeXHRRequest(chatx_server + 'dynamic_js2.php', 'GET').then(function(response) {
parsedResponse = JSON.parse(response);
setDynamicAuthenticationVars();
if (data.success) {
document.querySelector(".chxicon-refresh").click();
} else {
if (!document.querySelector(".chx-login-form chx_p")) {
const p = document.createElement("chx_p");
p.textContent = data.message;
document.querySelector(".chx-login-form").appendChild(p);
}
setTimeout(function() {
document.querySelector(".chx-login-form chx_p").remove();
}, 2000);
}
});
}
};
xhr.send(new URLSearchParams(new FormData(this)).toString());
e.preventDefault();
}
});
}
Поделиться1062023-03-24 02:25 pm
function ajaxFormSubmitted() {
setRegForm();
console.log("ajaxformsubmitted")
const forms = document.querySelectorAll(".chx-login-form form");
forms.forEach(form => {
form.addEventListener("submit", function(e) {
const activeForm = e.target.form;
const xhr = new XMLHttpRequest();
xhr.open("POST", `${chatx_server}client/auth.php`, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
store.setJWT(data.jwt);
makeXHRRequest(chatx_server + 'dynamic_js2.php', 'GET').then(function(response) {
parsedResponse = JSON.parse(response);
setDynamicAuthenticationVars();
if (data.success) {
document.querySelector(".chxicon-refresh").click();
} else {
if (!activeForm.querySelector("chx_p")) {
const p = document.createElement("chx_p");
p.textContent = data.message;
activeForm.appendChild(p);
}
setTimeout(function() {
activeForm.querySelector("chx_p").remove();
}, 2000);
}
});
}
};
xhr.send(new URLSearchParams(new FormData(activeForm)).toString());
e.preventDefault();
});
});
}
Поделиться1072023-03-24 02:38 pm
function ajaxFormSubmitted() {
setRegForm();
console.log("ajaxformsubmitted");
const forms = document.querySelectorAll(".chx-login-form form");
forms.forEach(form => {
form.addEventListener("submit", function(e) {
const activeForm = e.target.form;
const payload = new FormData(activeForm);
const xhr = new XMLHttpRequest();
xhr.open("POST", `${chatx_server}client/auth.php`, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
store.setJWT(data.jwt);
makeXHRRequest(chatx_server + 'dynamic_js2.php', 'GET').then(function(response) {
parsedResponse = JSON.parse(response);
setDynamicAuthenticationVars();
if (data.success) {
document.querySelector(".chxicon-refresh").click();
} else {
if (!activeForm.querySelector("chx_p")) {
const p = document.createElement("chx_p");
p.textContent = data.message;
activeForm.appendChild(p);
}
setTimeout(function() {
activeForm.querySelector("chx_p").remove();
}, 2000);
}
});
}
};
xhr.send(new URLSearchParams(payload).toString());
e.preventDefault();
});
});
}
Поделиться1082023-03-24 02:47 pm
function ajaxFormSubmitted() {
setRegForm();
console.log("ajaxformsubmitted");
const forms = document.querySelectorAll(".chx-login-form form");
forms.forEach(form => {
form.addEventListener("submit", function(e) {
const activeForm = e.target.form;
const payload = new FormData(activeForm);
const xhr = new XMLHttpRequest();
xhr.open("POST", `${chatx_server}client/auth.php`, true);
xhr.withCredentials = true;
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
store.setJWT(data.jwt);
makeXHRRequest(chatx_server + 'dynamic_js2.php', 'GET').then(function(response) {
parsedResponse = JSON.parse(response);
setDynamicAuthenticationVars();
if (data.success) {
document.querySelector(".chxicon-refresh").click();
} else {
if (!activeForm.querySelector("chx_p")) {
const p = document.createElement("chx_p");
p.textContent = data.message;
activeForm.appendChild(p);
}
setTimeout(function() {
activeForm.querySelector("chx_p").remove();
}, 2000);
}
});
}
};
xhr.send(new URLSearchParams(payload).toString());
e.preventDefault();
});
});
}
Поделиться1092023-03-27 12:27 am
const store = {};
// Inserts the jwt to the store object
store.setJWT = function(data) {
this.JWT = data;
localStorage.setItem('chx_authentication', data);
};store.setJWT(localStorage.getItem('chx_authentication'));
Поделиться1102023-03-27 12:30 am
const store = {}; // Set the cookie expiration date var date = new Date(); date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); // expires in 30 days // Inserts the jwt to the store object and set the cookie store.setJWT = function(data) { this.JWT = data; document.cookie = "chx_authentication=" + data + "; expires=" + date.toUTCString() + "; path=/"; }; // Read the cookie and set the JWT in the store object var cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)chx_authentication\s*\=\s*([^;]*).*$)|^.*$/, "$1"); store.setJWT(cookieValue);
Быстрый ответ
Похожие темы
Космос | Обои для рабочего стола | 2025-01-03 |