示例#1
0
/*
 * Notes:
 *  - Add CSRF protection anywhere where a user may enter data. Add 'csrf-middleware' before 'csrf'
 *  - Add UnauthenticatedAccessMiddleware whenever a user should be authenticated to access a page.
*/
$app->get('/', function (Request $request, Response $response, array $args) {
    //TODO pull recipes from database, store into objects, pass objects to home.twig
    $container = new \Zend\Session\Container('authentication');
    $user = $container->user;
    $this->view->render($response, 'templates/home.twig', array('user' => $user));
})->setName('home')->add($container->get('csrf-middleware'))->add($container->get('csrf'));
$app->get('/login', function (Request $request, Response $response, array $args) {
    $this->view->render($response, 'templates/login-page.twig');
})->setName('login')->add($container->get('csrf-middleware'))->add($container->get('csrf'));
$app->get('/register', function (Request $request, Response $response, array $args) {
    $this->view->render($response, 'templates/register-page.twig');
})->setName('register')->add($container->get('csrf-middleware'))->add($container->get('csrf'));
$app->get('/verify/{key}', function (Request $request, Response $response, array $args) {
    $key = $args['key'];
    $success = $this->DatabaseService->verifyUser($key);
    $this->view->render($response, 'templates/user-verify.twig', array('success' => $success));
});
$app->get('/profile', function (Request $request, Response $response, array $args) {
    $container = new \Zend\Session\Container('authentication');
    $user = $container->user;
    $this->view->render($response, 'templates/edit-profile.twig', array('user' => $user));
})->setName('edit-profile')->add($container->get('csrf-middleware'))->add($container->get('csrf'))->add($container->get('unauth-access-middleware'));
/** TESTING! */
$app->get('/test', function (\Psr\Http\Message\ServerRequestInterface $req, Response $res, $args = []) {
    var_dump($req->getServerParams());
});