diff --git a/Comment.php b/Comment.php
deleted file mode 100644
index bff2e3c..0000000
--- a/Comment.php
+++ /dev/null
@@ -1,29 +0,0 @@
-db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']);
- $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
-
- public function create() {
- if(!isset($_SESSION['AUTHENTICATED'])) {
- die('not auth');
- header("Location: /");
- exit;
- }
-
- $sql = 'INSERT INTO comment (created_by, created_on, story_id, comment) VALUES (?, NOW(), ?, ?)';
- $stmt = $this->db->prepare($sql);
- $stmt->execute(array(
- $_SESSION['username'],
- $_POST['story_id'],
- filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
- ));
- header("Location: /story/?id=" . $_POST['story_id']);
- }
-
-}
\ No newline at end of file
diff --git a/Index.php b/Index.php
deleted file mode 100644
index a2aded6..0000000
--- a/Index.php
+++ /dev/null
@@ -1,42 +0,0 @@
-db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']);
- $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
-
- public function index() {
-
- $sql = 'SELECT * FROM story ORDER BY created_on DESC';
- $stmt = $this->db->prepare($sql);
- $stmt->execute();
- $stories = $stmt->fetchAll(PDO::FETCH_ASSOC);
-
- $content = '
';
-
- foreach($stories as $story) {
- $comment_sql = 'SELECT COUNT(*) as `count` FROM comment WHERE story_id = ?';
- $comment_stmt = $this->db->prepare($comment_sql);
- $comment_stmt->execute(array($story['id']));
- $count = $comment_stmt->fetch(PDO::FETCH_ASSOC);
- $content .= '
- -
- ' . $story['headline'] . '
- ' . $story['created_by'] . ' | ' . $count['count'] . ' Comments |
- ' . date('n/j/Y g:i a', strtotime($story['created_on'])) . '
-
- ';
- }
-
- $content .= '
';
-
- require 'layout.phtml';
- }
-}
-
diff --git a/MasterController.php b/MasterController.php
deleted file mode 100644
index 895be4d..0000000
--- a/MasterController.php
+++ /dev/null
@@ -1,52 +0,0 @@
-_setupConfig($config);
- }
-
- public function execute() {
- $call = $this->_determineControllers();
- $call_class = $call['call'];
- $class = ucfirst(array_shift($call_class));
- $method = array_shift($call_class);
- $o = new $class($this->config);
- return $o->$method();
- }
-
- private function _determineControllers()
- {
- if (isset($_SERVER['REDIRECT_BASE'])) {
- $rb = $_SERVER['REDIRECT_BASE'];
- } else {
- $rb = '';
- }
-
- $ruri = $_SERVER['REQUEST_URI'];
- $path = str_replace($rb, '', $ruri);
- $return = array();
-
- foreach($this->config['routes'] as $k => $v) {
- $matches = array();
- $pattern = '$' . $k . '$';
- if(preg_match($pattern, $path, $matches))
- {
- $controller_details = $v;
- $path_string = array_shift($matches);
- $arguments = $matches;
- $controller_method = explode('/', $controller_details);
- $return = array('call' => $controller_method);
- }
- }
-
- return $return;
- }
-
- private function _setupConfig($config) {
- $this->config = $config;
- }
-
-}
\ No newline at end of file
diff --git a/Story.php b/Story.php
deleted file mode 100644
index 3e4eaad..0000000
--- a/Story.php
+++ /dev/null
@@ -1,101 +0,0 @@
-db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']);
- $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
-
- public function index() {
- if(!isset($_GET['id'])) {
- header("Location: /");
- exit;
- }
-
- $story_sql = 'SELECT * FROM story WHERE id = ?';
- $story_stmt = $this->db->prepare($story_sql);
- $story_stmt->execute(array($_GET['id']));
- if($story_stmt->rowCount() < 1) {
- header("Location: /");
- exit;
- }
-
- $story = $story_stmt->fetch(PDO::FETCH_ASSOC);
-
- $comment_sql = 'SELECT * FROM comment WHERE story_id = ?';
- $comment_stmt = $this->db->prepare($comment_sql);
- $comment_stmt->execute(array($story['id']));
- $comment_count = $comment_stmt->rowCount();
- $comments = $comment_stmt->fetchAll(PDO::FETCH_ASSOC);
-
- $content = '
- ' . $story['headline'] . '
- ' . $story['created_by'] . ' | ' . $comment_count . ' Comments |
- ' . date('n/j/Y g:i a', strtotime($story['created_on'])) . '
- ';
-
- if(isset($_SESSION['AUTHENTICATED'])) {
- $content .= '
-
- ';
- }
-
- foreach($comments as $comment) {
- $content .= '
-
- ';
- }
-
- require_once 'layout.phtml';
-
- }
-
- public function create() {
- if(!isset($_SESSION['AUTHENTICATED'])) {
- header("Location: /user/login");
- exit;
- }
-
- $error = '';
- if(isset($_POST['create'])) {
- if(!isset($_POST['headline']) || !isset($_POST['url']) ||
- !filter_input(INPUT_POST, 'url', FILTER_VALIDATE_URL)) {
- $error = 'You did not fill in all the fields or the URL did not validate.';
- } else {
- $sql = 'INSERT INTO story (headline, url, created_by, created_on) VALUES (?, ?, ?, NOW())';
- $stmt = $this->db->prepare($sql);
- $stmt->execute(array(
- $_POST['headline'],
- $_POST['url'],
- $_SESSION['username'],
- ));
-
- $id = $this->db->lastInsertId();
- header("Location: /story/?id=$id");
- exit;
- }
- }
-
- $content = '
-
- ';
-
- require_once 'layout.phtml';
- }
-
-}
\ No newline at end of file
diff --git a/User.php b/User.php
deleted file mode 100644
index b2ca74c..0000000
--- a/User.php
+++ /dev/null
@@ -1,161 +0,0 @@
-db = new PDO($dsn, $dbconfig['user'], $dbconfig['pass']);
- $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
-
- public function create() {
- $error = null;
-
- // Do the create
- if(isset($_POST['create'])) {
- if(empty($_POST['username']) || empty($_POST['email']) ||
- empty($_POST['password']) || empty($_POST['password_check'])) {
- $error = 'You did not fill in all required fields.';
- }
-
- if(is_null($error)) {
- if(!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) {
- $error = 'Your email address is invalid';
- }
- }
-
- if(is_null($error)) {
- if($_POST['password'] != $_POST['password_check']) {
- $error = "Your passwords didn't match.";
- }
- }
-
- if(is_null($error)) {
- $check_sql = 'SELECT * FROM user WHERE username = ?';
- $check_stmt = $this->db->prepare($check_sql);
- $check_stmt->execute(array($_POST['username']));
- if($check_stmt->rowCount() > 0) {
- $error = 'Your chosen username already exists. Please choose another.';
- }
- }
-
- if(is_null($error)) {
- $params = array(
- $_POST['username'],
- $_POST['email'],
- md5($_POST['username'] . $_POST['password']),
- );
-
- $sql = 'INSERT INTO user (username, email, password) VALUES (?, ?, ?)';
- $stmt = $this->db->prepare($sql);
- $stmt->execute($params);
- header("Location: /user/login");
- exit;
- }
- }
- // Show the create form
-
- $content = '
-
- ';
-
- require_once 'layout.phtml';
-
- }
-
- public function account() {
- $error = null;
- if(!isset($_SESSION['AUTHENTICATED'])) {
- header("Location: /user/login");
- exit;
- }
-
- if(isset($_POST['updatepw'])) {
- if(!isset($_POST['password']) || !isset($_POST['password_check']) ||
- $_POST['password'] != $_POST['password_check']) {
- $error = 'The password fields were blank or they did not match. Please try again.';
- }
- else {
- $sql = 'UPDATE user SET password = ? WHERE username = ?';
- $stmt = $this->db->prepare($sql);
- $stmt->execute(array(
- md5($_SESSION['username'] . $_POST['password']), // THIS IS NOT SECURE.
- $_SESSION['username'],
- ));
- $error = 'Your password was changed.';
- }
- }
-
- $dsql = 'SELECT * FROM user WHERE username = ?';
- $stmt = $this->db->prepare($dsql);
- $stmt->execute(array($_SESSION['username']));
- $details = $stmt->fetch(PDO::FETCH_ASSOC);
-
- $content = '
- ' . $error . '
-
- ' . $details['username'] . '
- ' . $details['email'] . '
-
- ';
-
- require_once 'layout.phtml';
- }
-
- public function login() {
- $error = null;
- // Do the login
- if(isset($_POST['login'])) {
- $username = $_POST['user'];
- $password = $_POST['pass'];
- $password = md5($username . $password); // THIS IS NOT SECURE. DO NOT USE IN PRODUCTION.
- $sql = 'SELECT * FROM user WHERE username = ? AND password = ? LIMIT 1';
- $stmt = $this->db->prepare($sql);
- $stmt->execute(array($username, $password));
- if($stmt->rowCount() > 0) {
- $data = $stmt->fetch(PDO::FETCH_ASSOC);
- session_regenerate_id();
- $_SESSION['username'] = $data['username'];
- $_SESSION['AUTHENTICATED'] = true;
- header("Location: /");
- exit;
- }
- else {
- $error = 'Your username/password did not match.';
- }
- }
-
- $content = '
-
- ';
-
- require_once('layout.phtml');
-
- }
-
- public function logout() {
- // Log out, redirect
- session_destroy();
- header("Location: /");
- }
-}
\ No newline at end of file
diff --git a/Vagrantfile b/Vagrantfile
index 5c81259..6ad8074 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -1,28 +1,29 @@
-require 'json'
-require 'yaml'
+## first install vagrant hostmanager:
+# `$ vagrant plugin install vagrant-hostmanager`
-VAGRANTFILE_API_VERSION ||= "2"
-confDir = $confDir ||= File.expand_path("vendor/laravel/homestead", File.dirname(__FILE__))
+$script = <