From d72e85376dd578c9061f12252862a32941e01c27 Mon Sep 17 00:00:00 2001 From: 4d696e6820427569 Date: Tue, 8 Dec 2020 18:47:32 +0700 Subject: [PATCH] . --- addQuote.php | 18 ++++++++++ controller.php | 18 ++++++++++ login.php | 18 ++++++++++ model.php | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ register.php | 18 ++++++++++ styles.css | 21 ++++++++++++ view.php | 43 ++++++++++++++++++++++++ 7 files changed, 227 insertions(+) create mode 100644 addQuote.php create mode 100644 controller.php create mode 100644 login.php create mode 100644 model.php create mode 100644 register.php create mode 100644 styles.css create mode 100644 view.php diff --git a/addQuote.php b/addQuote.php new file mode 100644 index 0000000..4aa3bd2 --- /dev/null +++ b/addQuote.php @@ -0,0 +1,18 @@ +"; +echo ""; +echo ""; +echo ""; +echo ""; +echo "

Add a quote

"; +echo "
"; +echo "
"; +echo "
"; +echo "

"; +echo ""; +echo "
"; +echo "
"; +echo ""; +echo ""; +?> \ No newline at end of file diff --git a/controller.php b/controller.php new file mode 100644 index 0000000..af4b5b7 --- /dev/null +++ b/controller.php @@ -0,0 +1,18 @@ +getAllQuotations()); +elseif (isset($_POST)) { + // Register/login user + if (isset( $_POST[ "userName" ] ) && isset( $_POST[ "password" ] ) ) + echo ""; + + // Adding quote + if (isset( $_POST[ "addQuote" ] ) && isset( $_POST[ "author" ] ) ) { + $theDBA->addQuote($_POST[ "addQuote" ], $_POST[ "author" ]); + } +} \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..20986e4 --- /dev/null +++ b/login.php @@ -0,0 +1,18 @@ +"; +echo ""; +echo ""; +echo ""; +echo ""; +echo "

Login

"; +echo "
"; +echo "
"; +echo "
"; +echo "

"; +echo ""; +echo "
"; +echo "
"; +echo ""; +echo ""; +?> \ No newline at end of file diff --git a/model.php b/model.php new file mode 100644 index 0000000..dc50677 --- /dev/null +++ b/model.php @@ -0,0 +1,91 @@ +DB = new PDO($dataBase, $user, $password); + $this->DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (PDOException $e) { + echo ('Error establishing Connection'); + exit(); + } + } + + // Return a PHP array of all columns in all quotations + public function getAllQuotations() { + $sqlStmt = $this->DB->prepare("SELECT * FROM quotations"); + $sqlStmt->execute(); + return $sqlStmt->fetchAll(PDO::FETCH_ASSOC); + } + + // Return a PHP array of all columns in all quotations + public function getAllUsers() { + $sqlStmt = $this->DB->prepare("SELECT * FROM users"); + $sqlStmt->execute(); + return $sqlStmt->fetchAll(PDO::FETCH_ASSOC); + } + + // Return true if the given string $accountName's password matches the given string $psw, + // false if there no match or the user does not exist + public function verifyCredentials($accountName, $psw) { + $sqlStmt = $this->DB->prepare("SELECT username, password FROM users WHERE username='" . $accountName . "' AND password='" . $psw . "'"); + $sqlStmt->execute(); + return ! empty( $sqlStmt->fetchAll(PDO::FETCH_ASSOC) ); + } + + // Insert string $quote to the quotations table with the string $author of the quote. + // Set rating and flagged to default values of 0. added should be set to NOW() + public function addQuote($quote, $author) { + $sqlStmt = $this->DB->prepare("INSERT INTO quotations(quote, added, author, rating, flagged) values('" . $quote . "', NOW(), '" . $author . "', 0, 0)"); + return $sqlStmt->execute(); + } + + // Insert a new user. + public function addUser($accountName, $psw) { + $sqlStmt = $this->DB->prepare("INSERT INTO users(username, password) values('" . $accountName . "', '" . $psw . "')"); + return $sqlStmt->execute(); + + } +} + +// Run as CLI console app +//$theDBA = new DatabaseAdapter(); +// Testing code that should not be run when a part of MVC + +//$theDBA->addUser('Dakota','abcd'); +//$theDBA->addQuote('Mine too', 'Devon'); +/* +if ($theDBA->verifyCredentials('Kim', '1234')) + echo 'works' . PHP_EOL; +else + echo 'broken' . PHP_EOL; + +if (! $theDBA->verifyCredentials('Dakota', 'abXX')) + echo 'works' . PHP_EOL; +else + echo 'broken' . PHP_EOL; + +if (! $theDBA->verifyCredentials('Not Here', 'abXX')) + echo 'works' . PHP_EOL; +else + echo 'broken' . PHP_EOL; + +echo PHP_EOL; + +$arr = $theDBA->getAllQuotations(); +print_r($arr); +$arr = $theDBA->getAllUsers(); +print_r($arr); +*/ +?> \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..700395e --- /dev/null +++ b/register.php @@ -0,0 +1,18 @@ +"; +echo ""; +echo ""; +echo ""; +echo ""; +echo "

Register

"; +echo "
"; +echo "
"; +echo "
"; +echo "

"; +echo ""; +echo "
"; +echo "
"; +echo ""; +echo ""; +?> \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..571016f --- /dev/null +++ b/styles.css @@ -0,0 +1,21 @@ +h1 { + font-family: cursive; + text-align: center; +} + +.generalBox { + border-radius: 10px; + border: 3px solid black; + margin: 5px; + padding: 7px; + width: auto; +} + +.inputFields { + width: min-content; +} + +span { + margin: 4px; +} + diff --git a/view.php b/view.php new file mode 100644 index 0000000..b2eb70e --- /dev/null +++ b/view.php @@ -0,0 +1,43 @@ +"; +echo ""; +echo ""; +echo ""; +echo ""; +echo "

Quotation Service

"; +echo "
"; +echo ""; +echo ""; +?> + + \ No newline at end of file