Пример #1
0
//If no settings are found, then we should load configuration setup and skip anything else
if (ORM::for_table("acp_settings")->count() == 0) {
    include BASE_DIR . 'install/configure.php';
    $klein->dispatch();
    return;
}
$klein->respond('!@^(/auth/|/language/|/api/|/assets/)', function ($request, $response, $service, $app, $klein) use($core) {
    if (!$core->auth->isLoggedIn()) {
        if (!strpos($request->pathname(), "/ajax/")) {
            $service->flash('<div class="alert alert-danger">You must be logged in to access that page.</div>');
            $response->redirect('/auth/login')->send();
        } else {
            $response->code(403);
            $response->body('Not Authenticated.')->send();
        }
        $klein->skipRemaining();
    }
});
$klein->respond('@^/auth/', function ($request, $response, $service, $app, $klein) use($core) {
    if ($core->auth->isLoggedIn()) {
        // Redirect /auth/* requests to /index if they are logged in
        // Skips redirect on requests to /auth/logout and /auth/remote/*
        if (0 !== strpos($request->pathname(), "/auth/logout") && 0 !== strpos($request->pathname(), "/auth/remote/")) {
            $response->redirect('/index')->send();
            $klein->skipRemaining();
        }
    }
});
$klein->respond('/node/[*]', function ($request, $response, $service, $app, $klein) use($core) {
    if (!$core->auth->isServer()) {
        $response->code(403)->body($core->twig->render('errors/403.html'))->send();