Created
October 22, 2017 15:39
-
-
Save edlvj/1258c9eeda9a614b537c3c01e6c246ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/vendor/autoload.php'; | |
$app = new Silex\Application(); | |
$app['debug'] = true; | |
$app->register(new Silex\Provider\SecurityServiceProvider()); | |
$app['security.firewalls'] = array( | |
'secured' => array( | |
'pattern' => '^.*$', | |
'http' => true, | |
'users' => array( | |
// raw password is foo | |
'admin' => array('ROLE_ADMIN', '$2y$10$3i9/lVd8UOFIJ6PAMFt8gu3/r5g0qeCJvoSlLCsvMTythye19F77a'), | |
'student' => array('ROLE_STUDENT', '$2y$10$3i9/lVd8UOFIJ6PAMFt8gu3/r5g0qeCJvoSlLCsvMTythye19F77a'), | |
), | |
'logout' => array('logout_path' => '/logout'), | |
), | |
); | |
$app->boot(); | |
$app->register(new Silex\Provider\TwigServiceProvider(), array( | |
'twig.path' => __DIR__.'/templates', | |
)); | |
$function = new Twig_SimpleFunction('is_granted', function($role) use ($app){ | |
try { | |
return $app['security.authorization_checker']->isGranted($role); | |
} catch (Exception $e) { | |
return false; | |
} | |
}); | |
$app['twig']->addFunction($function); | |
$app->register(new DF\DoctrineMongoDb\Silex\Provider\DoctrineMongoDbProvider(), [ | |
'mongodb.options' => [ | |
'server' => 'mongodb://localhost:27017', | |
'options' => [ | |
'username' => 'edlvj', | |
'password' => '852258', | |
'db' => 'class_book' | |
] | |
] | |
]); | |
$app->get('/', function (Silex\Application $app) { | |
return $app['twig']->render('index.html.twig'); | |
}); | |
$app->get('/groups/', function (Silex\Application $app) { | |
return $app['twig']->render('index.html.twig'); | |
}); | |
$app->get('/groups/create/', function (Silex\Application $app) { | |
return $app['twig']->render('index.html.twig'); | |
}); | |
$app->run(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment