예제 #1
0
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->rememberMe();
$storage = new SessionStorage(null, null, $sessionManager);
$authBootstrap = new Bootstrap($app, $adapter, $acl);
$authBootstrap->setStorage($storage);
$authBootstrap->bootstrap();
require '../lib/notorm/NotORM.php';
$pdo = new PDO('mysql:dbhost=' . $hostname . ';dbname=' . $database . ';charset=utf8', $dbuser, $dbpassword);
$db = new NotORM($pdo);
/* Get users */
$app->get('/users', function () use($app, $db) {
    try {
        $users = array();
        foreach ($db->users() as $user) {
            $users[] = array('id' => $user['id'], 'fname' => $user['fname'], 'lname' => $user['lname'], 'title' => $user['title'], 'username' => $user['username'], 'role' => $user['role'], 'email' => $user['email'], 'status' => $user['status']);
        }
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($users);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
});
/* Get user id */
$app->get('/user/:id', function ($id) use($app, $db) {
    try {
        $app->response()->header('Content-Type', 'application/json');
        $user = $db->users()->where('id', $id);
        if ($data = $user->fetch()) {
            echo json_encode(array("id" => $data["id"], "fname" => $data["fname"], "lname" => $data["lname"], "title" => $data["title"], "username" => $data["username"], "role" => $data["role"], "email" => $data["email"], "status" => $data["status"]));
        } else {
            echo json_encode(array("status" => false, "message" => "User ID {$id} does not exist"));
        }
예제 #2
0
    $memberClass = $role == 'guest' ? 'hide' : '';
    $adminClass = $role != 'admin' ? 'hide' : '';
    $data = array('hasIdentity' => $hasIdentity, 'role' => $role, 'identity' => $identity, 'memberClass' => $memberClass, 'adminClass' => $adminClass);
    $app->view->appendData($data);
});
$app->container->singleton('log', function () {
    $log = new \Monolog\Logger('slim-skeleton');
    $log->pushHandler(new \Monolog\Handler\StreamHandler('../logs/app.log', \Monolog\Logger::DEBUG));
    return $log;
});
// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true, 'debug' => true);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension(), new \Twig_Extension_Debug());
$app->get('/', function () use($app) {
    $data = array("intro" => "<div>\n                        <div class='jumbotron'>\n                            <div class='page-header'>\n                                <h1>Task App <small>Welcome to Task App</small></h1>\n                            </div>\n                            <p>This is a tiny user-task manager Application</p>\n                        </div>\n                    </div>");
    $app->render('frontpage.twig', $data);
});
$app->get('/tasks', function () use($app) {
    $app->render('tasks.twig');
});
$app->get('/users', function () use($app) {
    $app->render('users.twig');
});
// Login route MUST be named 'login'
$app->map('/login', function () use($app) {
    $username = null;
    if ($app->request()->isPost()) {
        $username = $app->request->post('username');
        $password = $app->request->post('password');
        $result = $app->authenticator->authenticate($username, $password);
        if ($result->isValid()) {