diff --git a/app/app.php b/app/app.php index 1f1cc05..977fdab 100644 --- a/app/app.php +++ b/app/app.php @@ -7,6 +7,7 @@ use Poche\Twig; use Symfony\Component\Translation\Loader\PoFileLoader; use Silex\Provider\SessionServiceProvider; +use Silex\Provider\SecurityServiceProvider; $app = new Silex\Application(); @@ -57,6 +58,25 @@ $app->register(new Silex\Provider\TranslationServiceProvider(), array( $app->register(new SessionServiceProvider()); +$app->register(new SecurityServiceProvider(), array( + 'security.firewalls' => array( + 'help' => array('pattern' => '^/help'), + 'default' => array( + 'pattern' => '^.*$', + 'anonymous' => true, + 'form' => array('login_path' => '/', 'check_path' => 'login'), + 'logout' => array('logout_path' => '/logout'), + 'users' => $app->share(function() use ($app) { + return new Poche\User\UserProvider($app['db']); + }), + ), + ), + 'security.access_rules' => array( + array('^/.+$', 'ROLE_USER'), + array('^/help$', ''), + ) +)); + $app['translator'] = $app->share($app->extend('translator', function($translator, $app) { $translator->addLoader('po', new PoFileLoader()); diff --git a/src/Poche/Controller/EntryController.php b/src/Poche/Controller/EntryController.php index 78f8ded..3105a59 100644 --- a/src/Poche/Controller/EntryController.php +++ b/src/Poche/Controller/EntryController.php @@ -15,7 +15,10 @@ class EntryController { $entries = $app['entry_api']->getEntries('unread'); - return $app['twig']->render('index.twig', array('entries' => $entries)); + return $app['twig']->render('index.twig', array( + 'error' => $app['security.last_error']($request), + 'entries' => $entries, + )); } public function showAction(Request $request, Application $app, $id)