예제 #1
0
파일: index.php 프로젝트: bgillet/slim-auth
<h1>SlimAuth - AccessControlManager class test page</h1>

<?php 
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
use Slim\Slim;
use BenGee\Slim\Db\SlimORM;
use BenGee\Slim\Auth\AccessControlManager;
use BenGee\Slim\Auth\RouteControlRule;
try {
    // ===========================
    // ====== INITIALISATION =====
    // ===========================
    $config = array(SlimORM::CONNECTIONS => array(SlimORM::DEFAULT_CNX => array(SlimORM::DSN => 'mysql:host=localhost;port=3306;dbname=slim', SlimORM::USR => 'root', SlimORM::PWD => 'rootsdev', SlimORM::OPT => null)), 'debug' => false);
    $app = new \Slim\Slim($config);
    $app->error(function (\Exception $e) use($app) {
        throw $e;
    });
    SlimORM::register($app);
    AccessControlManager::register($app);
    $app->auth->enableRouteControl(true);
    // ==========================
    // ===== PAGE D'ACCUEIL =====
    // ==========================
    $app->map('/', function () use($app) {
        if ($app->auth->isRouteControlEnabled()) {
            ?>
			<fieldset>
				<legend>Test links to check route access control</legend>
				<p><a href="access_all">All</a> : This page should be accessible to anybody !</p>
				<p><a href="access_public">Public</a> : This page should be accessible only to guests !</p>
				<p><a href="access_members">Members</a> : This page should be accessible only to identified members !</p>