Шитпостинг

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Шитпостинг » Обои для рабочего стола » Авиация


Авиация

Сообщений 101 страница 110 из 134

101

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);

102

let clicked = false;
const myButton = document.getElementById('myButton');
myButton.addEventListener('click', function() {
  clicked = true;
});

103

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!');
  }
});

104

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
});

105

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();
            }
        });
    }

106

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();
        });
    });
}

107

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();
        });
    });
}

108

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();
    });
  });
}

109

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'));

110

Код:
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);

Быстрый ответ

Напишите ваше сообщение и нажмите «Отправить»


Похожие темы


Вы здесь » Шитпостинг » Обои для рабочего стола » Авиация