Skip to content

Commit

Permalink
added controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
asilvafx committed Nov 10, 2024
1 parent dbc1ffc commit 56b07a2
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/core/controllers/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

//! Base controller
class BaseController {

protected
$db;

//! HTTP route pre-processor
function beforeroute($f3) {
}

//! HTTP route post-processor
function afterroute($f3) {

}

//! Instantiate class
function __construct() {
$f3=Base::instance();
}

}
59 changes: 59 additions & 0 deletions app/core/controllers/MainController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

//! Main controller
class MainController {

protected
$db;

//! HTTP route pre-processor
function beforeroute($f3) {

// Get server session auto_logout time
if($f3->get('SESSION.loggedin'))
{
$logout_time = $f3->get('auto_logout');
// Check if remember me true, set logout_time = 5 days
if($f3->get('SESSION.rememberme')){ $logout_time = "432000"; }
if(time() - $f3->get('SESSION.timestamp') > $logout_time)
{
// Clear user session and redirect to login page
$f3->set('SESSION.loggedin', false);
$f3->reroute('/'.$f3->get('SITE.uri_auth'));
}
else {
// Set timer
$f3->set('SESSION.timestamp', time());
}
}

}

//! HTTP route post-processor
function afterroute($f3) {

// Store CSRF in user session
$f3->set('SESSION.csrf', $f3->get('CSRF'));
// Store current time
$f3->set('time', time());
// Render HTML layout
$index_render = 'index.htm';
if(!file_exists($f3->get('UI').$index_render)){
$index_render = 'index.html';
}
if(!file_exists($f3->get('UI').$index_render)){
echo 'Invalid index file.'; die;
}
echo Template::instance()->render($index_render);
}

//! Instantiate class
function __construct() {
$f3=Base::instance();

$csrf = md5(uniqid(mt_rand(), true));
$f3->set('CSRF', $csrf);

}

}
23 changes: 23 additions & 0 deletions app/core/controllers/PostController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

//! Post controller
class PostController {

protected
$db;

//! HTTP route pre-processor
function beforeroute($f3) {
}

//! HTTP route post-processor
function afterroute($f3) {

}

//! Instantiate class
function __construct() {
$f3=Base::instance();
}

}

0 comments on commit 56b07a2

Please sign in to comment.