2024-12-25 23:02:09 +01:00
|
|
|
<?php
|
|
|
|
// Show errors and warnings
|
2024-12-26 14:44:40 +01:00
|
|
|
session_start();
|
2024-12-25 23:02:09 +01:00
|
|
|
ini_set('display_errors', '1');
|
|
|
|
ini_set('log_errors', '1');
|
|
|
|
ini_set('error_log', '../storage/logs/error_log.log');
|
|
|
|
|
|
|
|
define('models', __DIR__ . '/../app/models/');
|
|
|
|
define('views', __DIR__ . '/../app/views/');
|
|
|
|
define('controllers', __DIR__ . '/../app/controllers/');
|
2024-12-26 02:00:33 +01:00
|
|
|
define('config', __DIR__ . '/../config/');
|
2024-12-25 23:02:09 +01:00
|
|
|
|
2024-12-26 02:00:33 +01:00
|
|
|
require_once config . 'environment.php';
|
|
|
|
|
|
|
|
require_once '../core/Validator.php';
|
2024-12-25 23:02:09 +01:00
|
|
|
require_once '../core/Router.php';
|
|
|
|
require_once '../core/View.php';
|
|
|
|
require_once '../core/Controller.php';
|
2024-12-26 02:00:33 +01:00
|
|
|
require_once '../core/Database.php';
|
2024-12-26 14:44:40 +01:00
|
|
|
require_once '../core/middlewares/RequireAuth.php';
|
2024-12-26 02:00:33 +01:00
|
|
|
|
|
|
|
require_once models . 'User.php';
|
2024-12-26 18:47:00 +01:00
|
|
|
require_once models . 'Habit.php';
|
2024-12-25 23:02:09 +01:00
|
|
|
|
|
|
|
// Initialize router
|
|
|
|
$router = new Router();
|
2024-12-27 02:06:32 +01:00
|
|
|
if(!$_SESSION['user']) {
|
|
|
|
$router->add('/', 'HomeController@index');
|
|
|
|
} else {
|
|
|
|
$router->add('/', 'DashboardController@reroute', ['RequireAuth']);
|
|
|
|
}
|
2024-12-25 23:02:09 +01:00
|
|
|
|
|
|
|
// auth routes
|
2024-12-26 17:47:11 +01:00
|
|
|
$router->group('/auth', [], function ($router) {
|
|
|
|
$router->add('/signin', 'AuthController@signin');
|
|
|
|
$router->add('/signup', 'AuthController@signup');
|
|
|
|
$router->add('/logout', 'AuthController@logout');
|
|
|
|
});
|
|
|
|
|
|
|
|
// dashboard route
|
2024-12-27 02:06:32 +01:00
|
|
|
$router->add('/dashboard', 'DashboardController@index', ['RequireAuth']);
|
2024-12-26 17:47:11 +01:00
|
|
|
|
|
|
|
// habits routes
|
|
|
|
$router->group('/habits', ['RequireAuth'], function ($router) {
|
|
|
|
$router->add('', 'HabitController@index');
|
|
|
|
$router->add('/create', 'HabitController@create');
|
|
|
|
$router->add('/edit/{id}', 'HabitController@edit');
|
|
|
|
$router->add('/delete/{id}', 'HabitController@delete');
|
|
|
|
});
|
|
|
|
|
2024-12-25 23:02:09 +01:00
|
|
|
$router->dispatch();
|