init
This commit is contained in:
parent
7428ff8b8f
commit
9b15ac9fd3
87 changed files with 4975 additions and 1 deletions
165
public/index.php
Normal file
165
public/index.php
Normal file
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
//
|
||||
// It all starts here..
|
||||
//
|
||||
use app\app;
|
||||
use app\controllers\account;
|
||||
use app\controllers\category;
|
||||
use app\controllers\cart;
|
||||
use app\controllers\checkout;
|
||||
use app\controllers\home;
|
||||
use app\controllers\lnurlp;
|
||||
use app\controllers\lost;
|
||||
use app\controllers\magic_link;
|
||||
use app\controllers\support;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Load environment variables from the .env file at project root
|
||||
Dotenv\Dotenv::createImmutable(__DIR__ . '/../')->load();
|
||||
|
||||
// Start the session
|
||||
app::init_db();
|
||||
use app\models\addresses;
|
||||
use app\models\carts;
|
||||
use app\models\magic_links;
|
||||
use app\models\orders;
|
||||
use app\models\products;
|
||||
use app\models\user_addresses;
|
||||
use app\models\users;
|
||||
|
||||
if (!app::$db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='users'")->fetch()) {
|
||||
addresses::init();
|
||||
carts::init();
|
||||
magic_links::init();
|
||||
orders::init();
|
||||
products::init();
|
||||
user_addresses::init();
|
||||
users::init();
|
||||
}
|
||||
|
||||
session_start();
|
||||
session_regenerate_id(true); // prevent session fixation attacks
|
||||
|
||||
// prevent session hijack
|
||||
if (!isset($_SESSION['fingerprint'])) {
|
||||
$_SESSION['fingerprint'] = hash('sha256', $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
|
||||
} else {
|
||||
if ($_SESSION['fingerprint'] !== hash('sha256', $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'])) {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// these will be available to use in all twig templates
|
||||
$defaults = [
|
||||
'copyright_year' => date('Y'),
|
||||
'session' => $_SESSION,
|
||||
'env' => $_ENV,
|
||||
// uses cookie-js to get the client's preferred theme
|
||||
// used to conditionally deliver image assets
|
||||
// or styles based on theme
|
||||
'theme' => isset($_COOKIE["theme"]) ? $_COOKIE["theme"] : 'light',
|
||||
// set your tailwind colors here for app themeing
|
||||
// the idea is to avoid using colors in your templates
|
||||
'colors' => [
|
||||
'header' => [
|
||||
'banner' => 'bg-gray-100 dark:bg-gray-600 text-gray-200 dark:text-gray-200',
|
||||
|
||||
],
|
||||
'anchor' => [
|
||||
'primary' => 'text-blue-400 dark:text-blue-200'
|
||||
],
|
||||
'body' => 'bg-white dark:bg-gray-800 text-gray-600 dark:text-gray-300',
|
||||
'button' => [
|
||||
'primary' => 'border-blue-400 dark:border-blue-600 dark:hover:border-blue-800 bg-blue-400 dark:bg-blue-600 hover:bg-blue-600 hover:dark:bg-blue-800 text-white dark:text-white',
|
||||
'default' => 'hover:bg-gray-50 dark:hover:bg-gray-900'
|
||||
],
|
||||
'breadcrumb' => [
|
||||
'parent' => 'text-gray-300 dark:text-gray-400 hover:text-gray-400 dark:hover:text-gray-500',
|
||||
'seperator' => 'text-gray-200 dark:text-gray-200',
|
||||
'child' => 'text-gray-200 dark:text-gray-300'
|
||||
],
|
||||
'dropdown' => [
|
||||
'list' => 'bg-white dark:bg-blue-900 border-gray-600 dark:border-gray-300',
|
||||
'item' => 'hover:bg-gray-200 dark:hover:bg-gray-900'
|
||||
],
|
||||
'input' => 'text-gray-800 dark:text-gray-300 bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-500 focus:ring-blue-500',
|
||||
'error' => [
|
||||
'text' => 'text-red-600',
|
||||
'alert' => 'bg-red-100 text-gray-800 border-red-600'
|
||||
],
|
||||
'warning' => [
|
||||
'text' => 'text-yellow-400',
|
||||
'alert' => 'bg-yellow-100 text-gray-800 border-yellow-400'
|
||||
],
|
||||
'success' => [
|
||||
'text' => 'text-green-600',
|
||||
'alert' => 'bg-green-100 text-gray-800 border-green-600'
|
||||
],
|
||||
'info' => [
|
||||
'text' => 'text-blue-400',
|
||||
'alert' => 'bg-blue-200 text-gray-800 border-blue-400'
|
||||
],
|
||||
'modal' => [
|
||||
'content' => 'bg-white dark:bg-blue-900 border-gray-600 dark:border-gray-300',
|
||||
'shadow' => 'bg-black/70'
|
||||
],
|
||||
'nav' => [
|
||||
'bar' => 'bg-blue-400 dark:bg-blue-600 text-gray-200 dark:text-gray-200',
|
||||
'item' => 'hover:bg-blue-600 dark:hover:bg-blue-800 hover:text-gray-200 dark:hover:text-gray-300 text-white border-blue-400 dark:border-blue-600',
|
||||
'hovercontent' => 'bg-white dark:bg-slate-700 text-gray-800 dark:text-gray-300'
|
||||
],
|
||||
'rule' => 'border-gray-400 dark:border-gray-400',
|
||||
'text' => [
|
||||
'muted' => 'text-gray-400 dark:text-gray-300'
|
||||
],
|
||||
'toggle' => "bg-gray-300 peer-checked:bg-green-400 after:bg-white",
|
||||
'footer' => [
|
||||
"primary" => "bg-gray-200 dark:bg-slate-600 text-gray-500 dark:text-gray-300",
|
||||
"policy" => "bg-slate-400 dark:bg-slate-800 text-gray-200 dark:text-gray-400"
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
// Setup a twig
|
||||
$loader = new \Twig\Loader\FilesystemLoader(paths: dirname(__DIR__) . '/src/views');
|
||||
$GLOBALS['twig'] = new \Twig\Environment($loader, [
|
||||
//'cache' => dirname(__DIR__) . '/cache',
|
||||
'cache' => false,
|
||||
]);
|
||||
|
||||
$route = explode(separator: '?', string: $_SERVER['REQUEST_URI'])[0];
|
||||
if (str_starts_with(haystack: $route, needle: '/.well-known/lnurlp/')) {
|
||||
$route = '/lnurlp';
|
||||
}
|
||||
|
||||
$controller = match ($route) {
|
||||
'/' => home::index($defaults),
|
||||
'/account' => account::index($defaults),
|
||||
'/account/profile' => account::profile(),
|
||||
'/account/login' => account::login($defaults),
|
||||
'/account/logout' => account::logout(),
|
||||
'/magic-link' => magic_link::index(),
|
||||
'/account/returns' => account::returns($defaults),
|
||||
'/account/signup' => account::signup($defaults),
|
||||
'/account/billing' => account::billing($defaults),
|
||||
'/account/orders' => account::orders($defaults),
|
||||
'/account/shipping' => account::shipping($defaults),
|
||||
'/checkout/confirmed' => checkout::confirmed($defaults),
|
||||
'/checkout/review-pay' => checkout::review_pay($defaults),
|
||||
'/checkout/shipping-billing' => checkout::shipping_billing($defaults),
|
||||
'/support/ask' => support::index($defaults),
|
||||
'/support/bitcoin' => support::bitcoin($defaults),
|
||||
'/cart' => cart::index($defaults),
|
||||
'/lnurlp' => lnurlp::index(),
|
||||
// product categories
|
||||
'/power-meters' => category::power_meters($defaults),
|
||||
default => lost::index($defaults)
|
||||
};
|
||||
|
||||
// Clear alerts after rendering
|
||||
foreach (['error', 'warning', 'info', 'success'] as $alert) {
|
||||
unset($_SESSION[$alert]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue