/**
  * Este método se ejecuta antes que cualquier otro método.
  * Valida que el usuario exista y que la contraseña sea la correcta.
  * @throws UnauthorizedException
  */
 public function setup()
 {
     if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || isset($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['PHP_AUTH_PW']) && empty($_SERVER['PHP_AUTH_PW'])) {
         $this->logger->error("Intento de acceso sin usuario o contraseña");
         throw new UnauthorizedException("Usuario o contraseña incorrectos", Response::UNAUTHORIZED);
     }
     // valido usuario y contraseña
     $user = new UserController();
     try {
         if (!$user->isValid($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
             $this->logger->error("Intento de acceso con usuario o contraseña incorrectos");
             throw new UnauthorizedException("Usuario o contraseña incorrectos", Response::UNAUTHORIZED);
         }
     } catch (NotFoundException $ex) {
         $this->logger->error("Intento de acceso con usuario inexistente");
         throw new UnauthorizedException("Usuario o contraseña incorrectos", Response::UNAUTHORIZED);
     }
     $this->logger->info("Acceso con usuario: " . $_SERVER["PHP_AUTH_USER"]);
     return;
 }
Exemple #2
0
<?php

require '../../vendor/autoload.php';
use Controllers\UserController;
$correo = $_POST['email'];
$nombre = $_POST['name'];
$cumple = $_POST['birthday'];
$controlador = new UserController();
$controlador->guardar($cumple, $nombre);
Exemple #3
0
<?php

require '../vendor/autoload.php';
use Controllers\UserController;
session_start();
$id = $_SESSION['id'];
session_write_close();
if (!isset($id)) {
    header("Location: logIn.php");
}
$controller = new UserController();
$user = $controller->getUserId($id);
?>

<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="UTF-8">
	<title>Bienvenido</title>
	<?php 
include 'decorator.html';
?>
</head>
<body>
	<div class="container">
		<header class="container">
			<h2>Bienvenido <strong><?php 
echo $user->getFullName();
?>
</strong></h2>
		</header>
Exemple #4
0
    header('Content-type: text/html; charset=UTF-8');
    extract($data);
    include $fileName;
}
function url($path = '')
{
    return "http://192.168.33.22/" . $path;
}
/* ------------------------------------------------- *\
    Bootstrap App
\* ------------------------------------------------- */
use Models\Connect;
$database = ['dsn' => 'mysql:host=localhost;dbname=db_trombi', 'password' => 'root', 'username' => 'antoine'];
Connect::setDB($database);
use Controllers\UserController;
$userController = new UserController();
/* ------------------------------------------------- *\
    Request
\* ------------------------------------------------- */
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$method = strtolower($_SERVER["REQUEST_METHOD"]);
/* ------------------------------------------------- *\
    Router
\* ------------------------------------------------- */
if ($method == 'get') {
    switch ($uri) {
        case "/":
            $userController->index();
            break;
        case "/":
            $userController->index();
Exemple #5
0
<?php

require '../../vendor/autoload.php';
use Controllers\UserController;
if (isset($_POST['email']) && isset($_POST['password'])) {
    $controller = new UserController();
    $user = $controller->getUser($_POST['email'], $_POST['password']);
    $host = $_SERVER['HTTP_HOST'];
    $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    if ($user != NULL) {
        $extra = 'home.php';
        session_start();
        $_SESSION['id'] = $user->getId();
        session_write_close();
        header("Location: http://{$host}/demo/{$extra}");
    } else {
        $extra = 'login.php';
        header("Location: http://{$host}/demo/{$extra}");
    }
    exit;
}
Exemple #6
0
 public function __construct()
 {
     $this->app = Controller::routes();
     $this->appBase = $this->app->request()->getRootURI();
     $app = $this->app->setName('app');
     $authAdmin = function ($app) {
         return function ($app) {
             if (!isset($_SESSION['emailAdmin'])) {
                 $_SESSION['urlRedirect'] = $this->app->request()->getPathInfo();
                 $this->app->flash('error', 'Login required');
                 Controller::redirectTo('loginAdmin');
             }
         };
     };
     $authCustomer = function ($app) {
         return function ($app) {
             if (!isset($_SESSION['emailCustomer'])) {
                 $_SESSION['urlRedirect'] = $this->app->request()->getPathInfo();
                 $this->app->flash('error', 'Login required');
                 Controller::redirectTo('loginCustomer');
             }
         };
     };
     $this->app->notFound(function () {
         $this->app->render('not_found.twig', array('app_base' => $this->appBase, 'title' => 'Error 404'));
     });
     // Untuk memeriksa ada atau tidaknya nilai (hanya ada pada proses development)
     $this->app->get('/dev', function () {
         $this->app->render('dev.twig', array('var1' => isset($_SESSION['order_date']) ? sizeof($_SESSION['order_date']) : 'gak'));
     });
     $this->app->get('/', function () {
         ProductController::index('customer');
     })->name('indexHome');
     $this->app->get('/page/:id', function ($id) {
         ProductController::index('customer', $id);
     });
     $this->app->get('/carts', $authCustomer($app), function () {
         CartController::index();
     })->name('cart');
     $this->app->post('/products/show/:id', $authCustomer($app), function () {
         CartController::create();
     });
     $this->app->post('/carts/:id', $authCustomer($app), function ($id) {
         CartController::update($id);
     });
     $this->app->get('/carts/:id', $authCustomer($app), function ($id) {
         CartController::delete($id);
     });
     $this->app->get('/checkout', $authCustomer($app), function () {
         CheckoutController::index();
     });
     $this->app->post('/checkout', $authCustomer($app), function () {
         CheckoutController::create();
     });
     $this->app->get('/products/show/:id', function ($id) {
         ProductController::show($id);
     });
     $this->app->get('/login-admin', function () {
         if (isset($_SESSION['emailAdmin'])) {
             Controller::redirectTo('indexAdmin');
         } else {
             AdminController::loginAdmin();
         }
     })->name('loginAdmin');
     $this->app->post('/login-admin', function () {
         AdminController::loggedIn();
     });
     $this->app->get('/logout-admin', function () {
         AdminController::loggedOut();
     });
     $this->app->get('/login-customer', function () {
         if (isset($_SESSION['emailCustomer'])) {
             Controller::redirectTo('indexHome');
         } else {
             CustomerController::loginCustomer();
         }
     })->name('loginCustomer');
     $this->app->post('/login-customer', function () {
         CustomerController::loggedIn();
     });
     $this->app->get('/logout-customer', function () {
         CustomerController::loggedOut();
     });
     $this->app->get('/customer-profile', $authCustomer($app), function () {
         CustomerController::showCustomerProfile(isset($_SESSION['emailCustomer']) ? $_SESSION['emailCustomer'] : null);
     })->name('indexCustomerProfile');
     $this->app->get('/customer-profile/edit', $authCustomer($app), function () {
         CustomerController::editCustomerProfile(isset($_SESSION['emailCustomer']) ? $_SESSION['emailCustomer'] : null);
     });
     $this->app->post('/customer-profile/edit', $authCustomer($app), function () {
         CustomerController::updateCustomerProfile(isset($_SESSION['idCustomer']) ? $_SESSION['idCustomer'] : null);
     });
     $this->app->get('/admin', $authAdmin($app), function () {
         require_once 'CreateChart.php';
         AdminController::index();
     })->name('indexAdmin');
     $this->app->get('/admin/comments', $authAdmin($app), function () {
         CommentController::index();
     })->name('indexComment');
     $this->app->get('/admin/comments/page/:id', $authAdmin($app), function ($id) {
         CommentController::index($id);
     });
     $this->app->post('/add-comment', $authCustomer($app), function () {
         CommentController::create();
     });
     $this->app->get('/admin/carousels', $authAdmin($app), function () {
         CarouselController::index();
     })->name('indexCarousel');
     $this->app->get('/admin/carousels/page/:id', $authAdmin($app), function ($id) {
         CarouselController::index($id);
     });
     $this->app->get('/admin/carousels/new', $authAdmin($app), function () {
         CarouselController::add();
     });
     $this->app->post('/admin/carousels/new', $authAdmin($app), function () {
         CarouselController::create();
     });
     $this->app->get('/admin/carousels/edit/:id', $authAdmin($app), function ($id) {
         CarouselController::edit($id);
     });
     $this->app->post('/admin/carousels/edit/:id', $authAdmin($app), function ($id) {
         CarouselController::update($id);
     });
     $this->app->get('/admin/carousels/delete/:id', $authAdmin($app), function ($id) {
         CarouselController::delete($id);
     });
     $this->app->post('/admin/comments/:id', $authAdmin($app), function ($id) {
         CommentController::update($id);
     });
     $this->app->get('/admin/comments/delete/:id', $authAdmin($app), function ($id) {
         CommentController::delete($id);
     });
     $this->app->get('/admin/customers', $authAdmin($app), function () {
         CustomerController::index();
     })->name('indexCustomer');
     $this->app->get('/admin/customers/page/:id', $authAdmin($app), function ($id) {
         CustomerController::index($id);
     });
     $this->app->get('/admin/customers/new', $authAdmin($app), function () {
         CustomerController::add('admin');
     })->name('adminAddCustomer');
     $this->app->post('/admin/customers/new', $authAdmin($app), function () {
         CustomerController::create();
     });
     $this->app->get('/admin/customers/edit/:id', $authAdmin($app), function ($id) {
         CustomerController::edit($id);
     })->name('editCustomer');
     $this->app->post('/admin/customers/edit/:id', $authAdmin($app), function ($id) {
         CustomerController::update($id);
     });
     $this->app->get('/admin/customers/delete/:id', $authAdmin($app), function ($id) {
         CustomerController::delete($id);
     });
     $this->app->get('/new-customer', function () {
         CustomerController::add('customer');
     })->name('addCustomer');
     $this->app->post('/new-customer', function () {
         CustomerController::create('customer');
     });
     $this->app->get('/order-status', $authCustomer($app), function () {
         OrderController::orderStatus();
     })->name('indexOrderStatus');
     $this->app->get('/order-status/show-order-details/:id', $authCustomer($app), function ($id) {
         OrderController::showOrderDetail('customer', $id);
     });
     $this->app->post('/order-status/delete/:id', $authCustomer($app), function ($id) {
         OrderController::deleteOrderStatus($id);
     });
     $this->app->get('/admin/orders', $authAdmin($app), function () {
         OrderController::index();
     })->name('indexOrder');
     $this->app->get('/admin/orders/page/:id', $authAdmin($app), function ($id) {
         OrderController::index($id);
     });
     $this->app->get('/admin/orders/order_details/:id', $authAdmin($app), function ($id) {
         OrderController::showOrderDetail('admin', $id);
     });
     $this->app->post('/admin/orders/:id', $authAdmin($app), function ($id) {
         OrderController::update($id);
     });
     $this->app->get('/admin/orders/delete/:id', $authAdmin($app), function ($id) {
         OrderController::delete($id);
     });
     $this->app->get('/payment-confirmation', $authCustomer($app), function () {
         PaymentConfirmationController::add();
     })->name('newPaymentConfirmation');
     $this->app->post('/payment-confirmation', $authCustomer($app), function () {
         PaymentConfirmationController::create();
     });
     $this->app->post('/admin/payment_confirmations/:id', $authAdmin($app), function ($id) {
         PaymentConfirmationController::update($id);
     });
     $this->app->get('/admin/payment_confirmations/delete/:id', $authAdmin($app), function ($id) {
         PaymentConfirmationController::delete($id);
     });
     $this->app->get('/admin/payment_confirmations', $authAdmin($app), function () {
         PaymentConfirmationController::index();
     })->name('indexPaymentConfirmation');
     $this->app->get('/admin/payment_confirmations/page/:id', $authAdmin($app), function ($id) {
         PaymentConfirmationController::index($id);
     });
     $this->app->get('/admin/products', $authAdmin($app), function () {
         ProductController::index('admin');
     })->name('indexProduct');
     $this->app->get('/admin/products/page/:id', $authAdmin($app), function ($id) {
         ProductController::index('admin', $id);
     });
     $this->app->get('/admin/products/new', $authAdmin($app), function () {
         ProductController::add();
     })->name('addProduct');
     $this->app->post('/admin/products/new', $authAdmin($app), function () {
         ProductController::create();
     });
     $this->app->get('/admin/products/edit/:id', $authAdmin($app), function ($id) {
         ProductController::edit($id);
     })->name('editProduct');
     $this->app->post('/admin/products/edit/:id', $authAdmin($app), function ($id) {
         ProductController::update($id);
     });
     $this->app->get('/admin/products/delete/:id', $authAdmin($app), function ($id) {
         ProductController::delete($id);
     });
     $this->app->get('/admin/sales_report', function () {
         SalesReportController::index();
     });
     $this->app->get('/admin/sales_report/page/:id', $authAdmin($app), function ($id) {
         SalesReportController::index($id);
     });
     $this->app->post('/admin/sales_report', $authAdmin($app), function () {
         SalesReportController::indexByDate();
     });
     $this->app->get('/admin/users', $authAdmin($app), function () {
         UserController::index();
     })->name('indexUser');
     $this->app->get('/admin/users/page/:id', $authAdmin($app), function ($id) {
         UserController::index($id);
     });
     $this->app->get('/admin/users/new', function () {
         UserController::add();
     })->name('addUser');
     $this->app->post('/admin/users/new', function () {
         UserController::create();
     });
     $this->app->get('/admin/users/edit/:id', $authAdmin($app), function ($id) {
         UserController::edit($id);
     })->name('editUser');
     $this->app->post('/admin/users/edit/:id', $authAdmin($app), function ($id) {
         UserController::update($id);
     });
     $this->app->get('/admin/users/delete/:id', $authAdmin($app), function ($id) {
         UserController::delete($id);
     });
     $this->app->run();
 }