<?php $app->get('/', function () use($app) { require 'controllers/MainController.php'; $controller = new MainController(); $controller->index($app); }); $app->post('/registration', function () use($app) { require 'controllers/RegistrationController.php'; require 'models/RegistrationModel.php'; $controller = new RegistrationController(); $controller->index($app); }); $app->post('/auth', function () use($app) { require 'controllers/AuthController.php'; require 'models/AuthModel.php'; $controller = new AuthController(); $controller->index($app); });
<?php function check_logged_in() { BaseController::check_logged_in(); } $routes->get('/', function () { if ($user = AuthController::get_user_logged_in()) { AppController::index(); } else { AuthController::index(); } }); $routes->post('/login', function () { // Kirjautumisen käsittely AuthController::handle_login(); }); $routes->get('/logout', function () { AuthController::signout(); }); $routes->get('/signup', function () { AuthController::signup(); }); $routes->post('/signup', function () { AuthController::handle_signup(); }); $routes->get('/tasks/create', 'check_logged_in', function () { AppController::createTask(); }); $routes->post('/tasks/create', 'check_logged_in', function () { AppController::storeTask();