Skip to content

Commit

Permalink
Slim based project files
Browse files Browse the repository at this point in the history
  • Loading branch information
tony13tv committed Jun 16, 2015
1 parent 9deb4c6 commit 3011e28
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.idea/
assets/
templates_c/
composer.phar
vendor/
*.iml

# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"require": {
"slim/slim": "^2.6",
"vrana/notorm": "dev-master",
"twbs/bootstrap": "^3.3",
"slim/views": "^0.1.3",
"smarty/smarty": "^3.1"
}
}
264 changes: 264 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
session_start();
require_once 'vendor/autoload.php';
$app = new \Slim\Slim(array(
'view' => new \Slim\Views\Smarty()
));
$pdo = new PDO('mysql:host=localhost;dbname=slim_dcs', 'root', 'root');
$db = new NotORM($pdo);

$app->hook('slim.before.dispatch', function () use ($app) {
if (strpos($app->request()->getPathInfo(), '/admin') === 0) {
if (!isset($_SESSION['user'])) {
$app->redirectTo('login');
} else {
$app->view->setData(array('session' => true));
}
}
});

require_once 'security.php';

$app->group('/admin', function () use ($app, $db) {
$app->get('/:table', function ($table) use ($app, $db) {
$$table = $db->$table();
$app->render("admin/{$table}_index.tpl", compact("$table"));
});
});

$app->group('/api', function () use ($app, $db) {
$app->get('/:table', function ($table) use ($app, $db) {
$data = $db->$table();
$app->response->header('Content-Type', 'text/json');
$app->response->body(json_encode($data->jsonSerialize()));
});

$app->post('/:table', function ($table) use ($db) {
$$table = $db->$table();
});

$app->put('/:table/:id', function ($table, $id) use ($db) {
$$table = $db->$table();
});

$app->delete('/:table/:id', function ($table, $id) use ($db) {
$$table = $db->$table();
});
});

$app->run();
23 changes: 23 additions & 0 deletions security.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
$app->group('/security', function () use ($app, $db) {
$app->get('/login', function () use ($app) {
$app->render('admin/security.tpl');
})->setName('login');

$app->post('/login', function () use ($app, $db) {
$usuario = $db->usuario()->where(array(
'usuario' => $app->request->post('username'),
'contrasena' => md5($app->request->post('password'))
));
if (count($usuario) == 1) {
$_SESSION['user'] = $usuario[0]['usuario'];
$app->redirect('/slim-dcs/admin/pacientes');
}
$app->render('admin/security.tpl');
});

$app->get('/logout', function () use ($app) {
unset($_SESSION['user']);
$app->redirectTo('login');
})->setName('logout');
});
Loading

0 comments on commit 3011e28

Please sign in to comment.