diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 09ad82f1..e1a4310d 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -1,17 +1,38 @@ context->loggedIn = false; + if (isset($_SESSION['user-id'])) + { + $this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]); + if (!empty($this->context->user)) + { + $this->context->loggedIn = true; + } + } + if (empty($this->context->user)) + { + #todo: construct anonymous user + $this->context->user = null; + } + } + public function workWrapper($workCallback) { + $this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/'; + R::setup('sqlite:' . $this->config->main->dbPath); session_start(); + $this->context->layoutName = isset($_GET['json']) ? 'layout-json' : 'layout-normal'; $this->context->transport = new StdClass; $this->context->transport->success = null; - $this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/'; - R::setup('sqlite:' . $this->config->main->dbPath); + $this->attachUser(); + if (empty($this->context->route)) { $this->context->viewName = 'error-404'; diff --git a/src/Controllers/AbstractController.php b/src/Controllers/AbstractController.php index 2e7e8a6e..c0ebe266 100644 --- a/src/Controllers/AbstractController.php +++ b/src/Controllers/AbstractController.php @@ -1,28 +1,8 @@ context->loggedIn = false; - if (isset($_SESSION['user-id'])) - { - $this->context->user = R::findOne('user', 'id = ?', [$_SESSION['user-id']]); - if (!empty($this->context->user)) - { - $this->context->loggedIn = true; - } - } - if (empty($this->context->user)) - { - #todo: construct anonymous user - $this->context->user = null; - } - } - public function workWrapper($workCallback) { - $this->attachUser(); - try { $workCallback(); diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index d99db8d3..d48e5815 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -15,7 +15,7 @@ class AuthController extends AbstractController //check if already logged in if ($this->context->loggedIn) { - \Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search')); + \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); return; } @@ -38,7 +38,7 @@ class AuthController extends AbstractController throw new SimpleException('You haven\'t confirmed your e-mail address yet'); $_SESSION['user-id'] = $dbUser->id; - \Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search')); + \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); $this->context->transport->success = true; } } @@ -51,7 +51,7 @@ class AuthController extends AbstractController $this->context->viewName = null; $this->context->viewName = null; unset($_SESSION['user-id']); - \Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search')); + \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); } /** @@ -62,7 +62,7 @@ class AuthController extends AbstractController //check if already logged in if ($this->context->loggedIn) { - \Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search')); + \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); return; } @@ -167,7 +167,7 @@ class AuthController extends AbstractController if (!$emailActivation and !$adminActivation) { $_SESSION['user-id'] = $dbUser->id; - $this->attachUser(); + \Chibi\Registry::getBootstrap()->attachUser(); } } } @@ -180,7 +180,7 @@ class AuthController extends AbstractController //check if already logged in if ($this->context->loggedIn) { - \Chibi\HeadersHelper::set('Location', \Chibi\UrlHelper::route('post', 'search')); + \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('index', 'index')); return; } @@ -203,7 +203,7 @@ class AuthController extends AbstractController if (!$adminActivation) { $_SESSION['user-id'] = $dbUser->id; - $this->attachUser(); + \Chibi\Registry::getBootstrap()->attachUser(); } } } diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php new file mode 100644 index 00000000..64fcaffb --- /dev/null +++ b/src/Controllers/CommentController.php @@ -0,0 +1,11 @@ +posts = []; - $tp->posts []= 1; - $tp->posts []= 2; - $this->context->transport = $tp; + throw new Exception('Not implemented'); + } + + /** + * @route /post/upload + */ + public function uploadAction() + { + throw new Exception('Not implemented'); + } + + /** + * @route /post/{id} + */ + public function showAction($id) + { + throw new Exception('Not implemented'); } } diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php new file mode 100644 index 00000000..4ed9f534 --- /dev/null +++ b/src/Controllers/TagController.php @@ -0,0 +1,11 @@ +
-