public function logout(Request $request, Response $response) { $loader = new Twig_Loader_Filesystem('../views/twig'); $twig = new Twig_Environment($loader, array('cache' => false)); $user = new user(); $user->logout(); header("Location: /"); return $response; }
public function create($title, $image, $text) { if (!empty($title) && !empty($image) && !empty($text)) { $imageURL = $this->prepareImage($image); $user = new user(); $postID = $this->prepareText($text); $stmt = $this->pdo->prepare("INSERT INTO posts SET authorID = :authorID , title = :title, bgURL = :bgURL, postID = :postID, dateCreated = :dateCreated"); $stmt->execute(['authorID' => $user->getUser()->id, 'title' => $title, 'bgURL' => $imageURL, 'postID' => $postID, 'dateCreated' => Carbon::now()]); return true; } return false; }
public function show(Request $request, Response $response, array $args) { $pdo = Database::getPDO(); $loader = new Twig_Loader_Filesystem('../views/twig'); $twig = new Twig_Environment($loader, array('cache' => false)); $user = new user(); $post = new post($pdo); if ($user->checkSessionLogin()) { echo $twig->render("showArticle.twig", ['username' => $user->getUser()->firstName, 'post' => $post->loadPost($args['id']), 'language' => $_SESSION['language']]); return $response; } echo $twig->render("showArticle.twig", ['post' => $post->loadPost($args['id']), 'language' => $_SESSION['language']]); return $response; }
public function register(Request $request, Response $response, array $args) { $loader = new Twig_Loader_Filesystem('../views/twig'); $twig = new Twig_Environment($loader, array('cache' => false)); $user = new user(); if ($user->checkSessionLogin()) { header("Location: /"); return $response; } $credentials = ['username' => $_POST['username'], 'password' => $_POST['password'], 'email' => $_POST['email'], 'first_name' => $_POST['firstname'], 'last_name' => $_POST['lastname']]; $validation = new validation(); if (!$validation->validate($credentials)) { echo $twig->render("reg.twig", ['errors' => $validation->returnErrors(), 'language' => $_SESSION['language']]); return $response; } if ($user->register($credentials)) { echo $twig->render("reg.twig", ['confirmation' => "Registration complete!", 'language' => $_SESSION['language']]); return $response; } return $response; }
public function action(Request $request, Response $response) { $loader = new Twig_Loader_Filesystem('../views/twig'); $twig = new Twig_Environment($loader, array('cache' => false)); $user = new user(); if ($user->checkSessionLogin()) { echo $twig->render("account.twig", ['username' => $user->getUser()->firstName, 'email' => $user->getUser()->email, 'firstname' => $user->getUser()->firstName, 'lastname' => $user->getUser()->lastName, 'language' => $_SESSION['language']]); return $response; } echo $twig->render("login.twig", ['language' => $_SESSION['language']]); return $response; }