You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
908 B

9 years ago
9 years ago
9 years ago
  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class Controller {
  5. private function _is_logged_in(&$request, &$response) {
  6. session_start();
  7. if(!array_key_exists('user_id', $_SESSION)) {
  8. session_destroy();
  9. $response->setStatusCode(302);
  10. $response->headers->set('Location', '/login?return_to='.$request->getPathInfo());
  11. return false;
  12. } else {
  13. return true;
  14. }
  15. }
  16. public function index(Request $request, Response $response) {
  17. $response->setContent(view('index', [
  18. 'title' => 'Telegraph'
  19. ]));
  20. return $response;
  21. }
  22. public function dashboard(Request $request, Response $response) {
  23. if(!$this->_is_logged_in($request, $response)) {
  24. return $response;
  25. }
  26. $response->setContent(view('dashboard', [
  27. 'title' => 'Telegraph Dashboard'
  28. ]));
  29. return $response;
  30. }
  31. }