Beispiel #1
0
function authuser($role = 'member')
{
    $user = User::fetchFromDatabaseSomehow();
    if ($user->belongsToRole($role) === false) {
        Slim::flash('error', 'Login required');
        Slim::redirect('/login');
    }
}
Beispiel #2
0
 public function testSetFlashForNextRequest()
 {
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->flash('info', 'bar');
     });
     $this->assertFalse(isset($_SESSION['slim.flash']));
     $s->run();
     $this->assertEquals('bar', $_SESSION['slim.flash']['info']);
 }
Beispiel #3
0
require "libs/Simplepie/autoloader.php";
//Autoload para as Classes do SimplePie, para leitura de RSS
require "libs/Slim/Slim.php";
//Micro-framework Slim, para gerenciamento de rotas e alguns Helpers
include "app/funcoes.php";
//Funções próprias, como CSS, Javascript e Meta
include "app/config.php";
//Configurações gerais do sistema, através de Constantes.
date_default_timezone_set('America/Sao_Paulo');
$autoloader = new Autoloader();
$app = new Slim();
$app->contentType('text/html; charset=utf-8');
$app->add(new Slim_Middleware_SessionCookie(array('secret' => '98897qwer65465qwe9r79qw9e354as68dh56k6lks6df8g', 'expires' => '60 minutes')));
$authenticate = function ($app) {
    return function () use($app) {
        if (!isset($_SESSION['dehbora']['user'])) {
            $_SESSION['dehbora']['urlRedirect'] = $app->request()->getPathInfo();
            $app->flash('error', 'Você precisa se logar.');
            $app->redirect(URL_BASE . '/inicial');
        }
    };
};
$app->hook('slim.before.dispatch', function () use($app) {
    $user = null;
    if (isset($_SESSION['dehbora']['user'])) {
        $user = $_SESSION['dehbora']['user'];
    }
    $app->view()->setData('user', $user);
});
require_once "app/routes.php";
$app->run();
Beispiel #4
0
$app = new Slim(array('view' => new TwigView()));
////////////////////////////////////////////////////////////////////////////////
//--Routes--////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/* purpose: main page show normal fizbuz and the structure / forms for the rest of the roots.
 * 
 */
$app->get('/', function () use($app) {
    $args = array('numbers' => getNumberArray(1, 100));
    $app->render('index.twig', $args);
});
$app->get('/:num', function ($pNumber) use($app) {
    $args = array('number' => new FizBuzNumber($pNumber));
    $app->render('single.twig', $args);
});
//->conditions(array('num'=> 'd+'));
$app->get('/list/(:start-):end', function ($start = 1, $end) use($app) {
    if ($start >= $end) {
        $app->flash("error start has to be greater than end");
        //--TODO--/ redirect to first page.
    }
    $args = array('start' => $start, 'end' => $end, 'numbers' => getNumberArray($start, $end));
    $app->render('list.twig', $args);
});
/**
 * Step 4: Run the Slim application
 *
 * This method should be called last. This is responsible for executing
 * the Slim application using the settings and routes defined above.
 */
$app->run();
Beispiel #5
0
 /**
  * Slim Flash
  *
  * Pre-conditions:
  * Slim app sets Flash message for next request;
  *
  * Post-conditions:
  * Message is persisted to $_SESSION after app is run;
  */
 public function testSlimFlash()
 {
     $app = new Slim();
     $app->get('/', function () use($app) {
         $app->flash('info', 'Foo');
     });
     $app->run();
     $this->assertArrayHasKey('info', $_SESSION['flash']);
     $this->assertEquals('Foo', $_SESSION['flash']['info']);
 }