still some bugs and auth issues to iron out. need to implement a new action button/bar, the card for moments in a space, creating new moments and essays, dynamically refreshing the spaces view when a new post is created.

This commit is contained in:
2025-05-20 19:46:09 -06:00
parent a93c30c40f
commit 54a01f0f1f
20 changed files with 1018 additions and 1191 deletions
+9 -49
View File
@@ -1,18 +1,18 @@
<?php
session_start();
header("Content-Security-Policy: default-src 'self' localhost:7477; font-src 'self' https://www.nerdfonts.com/assets/fonts/Symbols-2048-em%20Nerd%20Font%20Complete.woff2; style-src 'self' 'unsafe-inline' https://nerdfonts.com/assets/css/webfont.css https://www.nerdfonts.com/assets/css/webfont.css; script-src 'self' 'unsafe-inline'; img-src 'self';");
header("Content-Security-Policy: default-src 'self' localhost:*; font-src 'self' https://www.nerdfonts.com/assets/fonts/Symbols-2048-em%20Nerd%20Font%20Complete.woff2; style-src 'self' 'unsafe-inline' https://nerdfonts.com/assets/css/webfont.css https://www.nerdfonts.com/assets/css/webfont.css; script-src 'self' 'unsafe-inline'; img-src 'self';");
// Initialize Composer.
require_once 'vendor/autoload.php';
require_once 'db.php';
require_once 'user.php';
require_once 'post.php';
require_once 'spaces.php';
// Load environment variables.
require_once 'functions/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable('/home/jashton/dev/me/weave.space/.env');
$dotenv->safeLoad();
require_once 'functions/db.php';
require_once 'functions/core.php';
require_once 'functions/user.php';
require_once 'functions/post.php';
require_once 'functions/space.php';
/**/
// Set SESSION variable.
if (!isset($_SESSION['initialized'])) {
$_SESSION['initialized'] = true;
@@ -25,43 +25,3 @@ if (!isset($_SESSION['initialized'])) {
define('owner', 1);
define('developer', 2);
define('user', 3);
// Update the database and cookies to keep the user logged in.
if (isset($_SESSION['user_id'])) {
$conn = get_connection();
$stmt = $conn->prepare('UPDATE user SET is_active = true WHERE user_id = ?');
$stmt->bind_param('i', $_SESSION['user_id']);
$stmt->execute();
$stmt = $conn->prepare('UPDATE user SET last_active = CURRENT_TIMESTAMP WHERE user_id = ?');
$stmt->bind_param('i', $_SESSION['user_id']);
$stmt->execute();
} else if (isset($_COOKIE['remember_user'])) {
$conn = get_connection();
$stmt = $conn->prepare('SELECT * FROM remember_user WHERE token = ?');
$stmt->bind_param('s', $_COOKIE['remember_user']);
$stmt->execute();
$remember = $stmt->get_result()->fetch_assoc();
if (hash('sha256', $_SERVER['REMOTE_ADDR']) != $remember['remote_addr'] || (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && hash('sha256', $_SERVER['HTTP_X_FORWARDED_FOR']) != $remember['forwarded_for'])) {
// TODO: Log the attempt to use a cookie from a different browser/device than the cookie was created
echo "Naughty, you are trying to use someone else's cookie...";
} else {
$stmt = $conn->prepare('SELECT user_id, username, role_id FROM user WHERE user_id = ?');
$stmt->bind_param('s', $remember['user_id']);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$_SESSION['user_id'] = $user['user_id'];
$_SESSION['username'] = $user['username'];
$_SESSION['role_id'] = $user['role_id'];
$stmt = $conn->prepare('UPDATE user SET is_active = true WHERE user_id = ?');
$stmt->bind_param('i', $_SESSION['user_id']);
$stmt->execute();
$stmt = $conn->prepare('UPDATE user SET last_active = CURRENT_TIMESTAMP WHERE user_id = ?');
$stmt->bind_param('i', $_SESSION['user_id']);
$stmt->execute();
}
}