diff --git a/5min/day21/index.html b/5min/day21/index.html new file mode 100644 index 0000000..0b75c6b --- /dev/null +++ b/5min/day21/index.html @@ -0,0 +1,12 @@ + + + + Day 21 + + + + + +

Hello cruel world!

+ + diff --git a/5min/day21/script.js b/5min/day21/script.js new file mode 100644 index 0000000..aff5515 --- /dev/null +++ b/5min/day21/script.js @@ -0,0 +1,4 @@ +document.addEventListener('DOMContentLoaded', function() { + let h2 = document.querySelector('h2'); + h2.innerText = 'The DOM is Magical'; +}); diff --git a/5min/day21/styles.css b/5min/day21/styles.css new file mode 100644 index 0000000..683dd33 --- /dev/null +++ b/5min/day21/styles.css @@ -0,0 +1,4 @@ +body { + background-color: indigo; + color: white; +} diff --git a/5min/day22/index.php b/5min/day22/index.php new file mode 100644 index 0000000..7eb535f --- /dev/null +++ b/5min/day22/index.php @@ -0,0 +1,14 @@ + + + + + Day 22 + + + + + +
+ + + diff --git a/catalog/js/script.js b/5min/day22/script.js old mode 100755 new mode 100644 similarity index 100% rename from catalog/js/script.js rename to 5min/day22/script.js diff --git a/5min/day22/styles.css b/5min/day22/styles.css new file mode 100644 index 0000000..64b2323 --- /dev/null +++ b/5min/day22/styles.css @@ -0,0 +1,20 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + height: 100vh; + width: 100%; + border: 1px solid red; +} + +.square { + position: absolute; + width: 200px; + height: 200px; + background-color: pink; + bottom: 0; + left: 0; +} diff --git a/catalog/css/style.css b/5min/day23/css/.gitkeep old mode 100755 new mode 100644 similarity index 100% rename from catalog/css/style.css rename to 5min/day23/css/.gitkeep diff --git a/5min/day23/css/styles.css b/5min/day23/css/styles.css new file mode 100644 index 0000000..99dd6a4 --- /dev/null +++ b/5min/day23/css/styles.css @@ -0,0 +1,6 @@ +div { + height: 100px; + width: 100px; + background-color: black; + border: 1px solid white; +} diff --git a/5min/day23/img/.gitkeep b/5min/day23/img/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day23/includes/.gitkeep b/5min/day23/includes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day23/index.php b/5min/day23/index.php new file mode 100644 index 0000000..e0e45bd --- /dev/null +++ b/5min/day23/index.php @@ -0,0 +1,17 @@ + + + + + Dummy Title + + + + + + '; + ?> + + + diff --git a/5min/day23/js/.gitkeep b/5min/day23/js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day23/js/index.js b/5min/day23/js/index.js new file mode 100644 index 0000000..08304e5 --- /dev/null +++ b/5min/day23/js/index.js @@ -0,0 +1,14 @@ +document.querySelectorAll('div').forEach((d) => { + d.style.backgroundColor = 'black'; + d.addEventListener('click', populate); +}) + +function populate() { + if (this.style.backgroundColor === 'black') { + this.style.backgroundColor = 'red'; + this.style.borderRadius = '50%'; + } else { + this.style.backgroundColor = 'black'; + this.style.borderRadius = '0%'; + } +} diff --git a/5min/day24/css/.gitkeep b/5min/day24/css/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day24/css/styles.css b/5min/day24/css/styles.css new file mode 100644 index 0000000..1603f03 --- /dev/null +++ b/5min/day24/css/styles.css @@ -0,0 +1,11 @@ +div { + position: absolute; + top: 0px; + height: 100px; + width: 100px; + background-color: black; +} + +button { + float: right; +} diff --git a/5min/day24/img/.gitkeep b/5min/day24/img/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day24/includes/.gitkeep b/5min/day24/includes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day24/index.php b/5min/day24/index.php new file mode 100644 index 0000000..73df3de --- /dev/null +++ b/5min/day24/index.php @@ -0,0 +1,15 @@ + + + + + Dummy Title + + + + + + +
+ + + diff --git a/5min/day24/js/.gitkeep b/5min/day24/js/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/5min/day24/js/index.js b/5min/day24/js/index.js new file mode 100644 index 0000000..fad689b --- /dev/null +++ b/5min/day24/js/index.js @@ -0,0 +1,9 @@ +const div = document.querySelector('div'); +const button = document.querySelector('button') + +let times = 1; +button.addEventListener('click', (e) => { + let px = 300 * times; + times++; + div.style.top = px + 'px'; +}); diff --git a/catalog/cart.php b/catalog/cart.php index e69de29..d70a86a 100755 --- a/catalog/cart.php +++ b/catalog/cart.php @@ -0,0 +1,13 @@ +Catalog'; + +echo '
'; +echo catalog_grid(fetch_catalog()); +echo '
'; + +include_once 'components/foot.php'; diff --git a/catalog/components/cart/item.php b/catalog/components/cart/item.php new file mode 100644 index 0000000..79c8484 --- /dev/null +++ b/catalog/components/cart/item.php @@ -0,0 +1,20 @@ + +
+
+ +
+

' . $item['description'] . '

+ + +
+ + '; + + return $item; +} diff --git a/catalog/components/foot.php b/catalog/components/foot.php new file mode 100644 index 0000000..e497e7c --- /dev/null +++ b/catalog/components/foot.php @@ -0,0 +1,18 @@ + + + + + diff --git a/catalog/components/head.php b/catalog/components/head.php new file mode 100644 index 0000000..75da5c7 --- /dev/null +++ b/catalog/components/head.php @@ -0,0 +1,21 @@ + + + + + + + '; + break; + case '/product.php': + if (!isset($_SESSION['id'])) + echo ''; + break; + } + ?> + + + + diff --git a/catalog/components/nav.php b/catalog/components/nav.php new file mode 100755 index 0000000..ec62844 --- /dev/null +++ b/catalog/components/nav.php @@ -0,0 +1,25 @@ + + + +'; + +echo $nav; diff --git a/catalog/components/products/card.php b/catalog/components/products/card.php new file mode 100644 index 0000000..034fc66 --- /dev/null +++ b/catalog/components/products/card.php @@ -0,0 +1,19 @@ + +
+ +
+ +
+

' . $product['name'] . '

+
' . $product['price'] . '
+
+ + '; + + return $card; +} diff --git a/catalog/components/products/grid.php b/catalog/components/products/grid.php new file mode 100644 index 0000000..94559fc --- /dev/null +++ b/catalog/components/products/grid.php @@ -0,0 +1,16 @@ + + '; + + foreach ($products as $p) + $grid .= product_card($p); + + $grid .= ' + + '; + + return $grid; +} diff --git a/catalog/components/products/list.php b/catalog/components/products/list.php new file mode 100644 index 0000000..e69de29 diff --git a/catalog/components/products/product.php b/catalog/components/products/product.php new file mode 100644 index 0000000..062eeed --- /dev/null +++ b/catalog/components/products/product.php @@ -0,0 +1,36 @@ + +
+ +
+
+
+

' . $product['name'] . '

+

' . $product['price'] . '

+
+ +

' . $product['description'] . '

+
+ +
+ + +
+ + +
+
+ + + + '; + + return $page; +} diff --git a/catalog/components/user/display.php b/catalog/components/user/display.php new file mode 100644 index 0000000..e69de29 diff --git a/catalog/components/user/login.php b/catalog/components/user/login.php new file mode 100644 index 0000000..522f3cd --- /dev/null +++ b/catalog/components/user/login.php @@ -0,0 +1,27 @@ + +
+
+
+ + +
+ +
+ + +
+ + Signup Instead + + +
+
+ + '; + + return $form; +} diff --git a/catalog/components/user/signup.php b/catalog/components/user/signup.php new file mode 100644 index 0000000..da36216 --- /dev/null +++ b/catalog/components/user/signup.php @@ -0,0 +1,40 @@ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ + Login Instead + +
+ + +
+ +
+

+

+

+

+
+
+ + '; + + return $form; +} diff --git a/catalog/composer.json b/catalog/composer.json new file mode 100644 index 0000000..f3fc2a2 --- /dev/null +++ b/catalog/composer.json @@ -0,0 +1,17 @@ +{ + "name": "violet/catalog", + "autoload": { + "psr-4": { + "Violet\\Catalog\\": "src/" + } + }, + "authors": [ + { + "name": "Josh Ashton", + "email": "me@joshashton.dev" + } + ], + "require": { + "vlucas/phpdotenv": "^5.6" + } +} diff --git a/catalog/create-account.php b/catalog/create-account.php index e69de29..79041ef 100755 --- a/catalog/create-account.php +++ b/catalog/create-account.php @@ -0,0 +1,18 @@ +Username is taken, or password do not match.

'; + else { + header('Location: catalog.php'); + } +} + +require_once 'components/head.php'; +require_once 'components/user/signup.php'; + +echo signup_form(); + +require_once 'components/foot.php'; diff --git a/catalog/css/base.css b/catalog/css/base.css new file mode 100755 index 0000000..ce53933 --- /dev/null +++ b/catalog/css/base.css @@ -0,0 +1,216 @@ +/********** GENERAL **********/ +* { + margin: 0; + padding: 0; +} + +h1 { + font-size: 6vw; +} + +h2 { + font-size: 4vw; +} + +h3 { + font-size: 3vw; +} + +h4 { + font-size: 2vw; +} + +h5, +h6, +p, +a, +label { + font-size: 1vw; +} + +/********** NAV BAR **********/ +nav { + margin-bottom: 25px; +} + +nav ul {} + +nav ul li { + display: inline-block; + list-style: none; +} + +nav ul li a { + display: block; + padding: 15px 15px 15px 15px; + text-decoration: none; +} + +/********** LAYOUT CLASSES **********/ +.absolute_h_center { + position: absolute; + left: 50%; + transform: translateX(-50%); +} + +.center { + text-align: center; + margin: 0 auto; +} + +.center_children { + align-items: center; + justify-content: center; +} + +.row { + display: flex; + flex-direction: row; +} + +.column { + display: flex; + flex-direction: column; +} + +.space_between { + justify-content: space-between; +} + +.grid { + display: grid; + grid-template-columns: 20% 20% 20% 20%; + column-gap: 75px; + row-gap: 25px; +} + +/********** CARDS **********/ +.card { + display: block; + width: 250px; + height: 250px; + border: 1px solid black; +} + +.product_page_card { + display: block; + border: 1px solid black; +} + +.card .img_container img { + min-width: 60%; + max-width: 60%; + height: auto; +} + +.product_page_card .img_container img { + min-width: 30%; + max-width: 30%; + height: auto; + border: 1px solid red; +} + +/********** MARGINS & PADDING **********/ +.padding { + padding: 25px; +} + +.padding-top { + padding-top: 25px; +} + +.padding-right { + padding-right: 25px; +} + +.padding-bottom { + padding-bottom: 25px; +} + +.padding-left { + padding-left: 25px; +} + +.margin { + margin: 25px; +} + +.margin-top { + margin-top: 25px; +} + +.margin-right { + margin-right: 25px; +} + +.margin-bottom { + margin-bottom: 25px; +} + +.margin-left { + margin-left: 25px; +} + +/********** SIZING **********/ +.std_width { + width: 70%; +} + +.full_width { + width: 100%; +} + +/********** MODALS **********/ +.modal { + display: none; + position: fixed; + z-index: 1; + padding-top: 100px; + left: 0; + top: 0; + width: 100%; + height: 100%; + overflow: auto; + backdrop-filter: blur(10px); +} + +.modal.fade-in { + display: block; + animation: fade-in 0.7s ease-in forwards; +} + +.modal.fade-out { + display: none; + animation: fade-out 0.7s ease-out forwards; +} + +.modal_content { + display: fit-content; + margin: auto; + width: 40%; + height: max-content; +} + +@keyframes fade-in { + 0% { + opacity: 0; + display: none; + } + + 100% { + opacity: 1; + display: block; + } +} + +@keyframes fade-out { + 0% { + opacity: 1; + display: block; + } + + 100% { + opacity: 0; + display: none; + } +} diff --git a/catalog/css/colors.css b/catalog/css/colors.css new file mode 100644 index 0000000..532138a --- /dev/null +++ b/catalog/css/colors.css @@ -0,0 +1,28 @@ +:root { + --bg: #EBF2FA; + --gold: #FFD700; + --brwn: #F4A460; + --blue: #1E90FF; + --red: #DC143C; +} + +nav { + background-color: var(--bg); + border-bottom: 2px solid var(--gold); +} + +nav *, +nav *:visited { + color: var(--blue); + text-decoration: none; + font-weight: 800; + transition-duration: 500ms; +} + +nav ul li a:hover { + background-color: var(--gold); +} + +body { + background-color: var(--bg); +} diff --git a/catalog/functions/base.php b/catalog/functions/base.php new file mode 100644 index 0000000..d149045 --- /dev/null +++ b/catalog/functions/base.php @@ -0,0 +1,38 @@ +'; + print_r($arg); + echo ''; + return ob_get_clean(); +} + +function random_string() +{ + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $rand_string = ''; + for ($i = 0; $i < 512; $i++) + $rand_string = $characters[rand(0, strlen($characters) - 1)]; + + return $rand_string; +} + +function verify_hash($arg, $hash_salt) +{ + list($salt_hex, $hash) = explode('.', $hash_salt, 2); + $salt = hex2bin($salt_hex); + $calculated_hash = hash('sha512', $salt . $arg . $_ENV['SALT']); + return hash_equals($hash, $calculated_hash); +} + +function hash_salt($arg = null) +{ + if (!$arg) + $arg = random_string(); + + $salt1 = random_bytes(256); + $salt2 = $_ENV['SALT']; + + return bin2hex($salt1) . '.' . hash('sha512', $salt1 . $arg . $salt2); +} diff --git a/catalog/functions/catalog.php b/catalog/functions/catalog.php new file mode 100644 index 0000000..33a7ebc --- /dev/null +++ b/catalog/functions/catalog.php @@ -0,0 +1,14 @@ +query('SELECT * FROM product'); + return $result; +} + +function fetch_product($id) +{ + $result = exec_stmt('SELECT * FROM product WHERE id = ?', 'i', $id); + return $result->fetch_assoc(); +} diff --git a/catalog/functions/db.php b/catalog/functions/db.php new file mode 100644 index 0000000..999a72f --- /dev/null +++ b/catalog/functions/db.php @@ -0,0 +1,39 @@ +prepare($stmt); + $stmt->bind_param($param_types, ...$args); + $stmt->execute(); + $result = $stmt->get_result(); + + if ($result) + return $result; + else + return mysqli_insert_id($conn); +} + +function get_connection() +{ + $conn = new mysqli(HOST, USER, PASS, DB); + return $conn; +} diff --git a/catalog/functions/init.php b/catalog/functions/init.php new file mode 100644 index 0000000..577fb2a --- /dev/null +++ b/catalog/functions/init.php @@ -0,0 +1,13 @@ +safeLoad(); + +require_once 'functions/db.php'; diff --git a/catalog/functions/user.php b/catalog/functions/user.php new file mode 100644 index 0000000..5da783e --- /dev/null +++ b/catalog/functions/user.php @@ -0,0 +1,62 @@ +safeLoad(); + + require_once 'base.php'; + require_once 'db.php'; + + switch ($_POST['form_id']) { + case 'create-account': + if (isset($_POST['username'])) { + $result['exists'] = (username_exists(urldecode($_POST['username'])) ? 'True' : 'False'); + echo json_encode($result); + } + break; + } +} + +function username_exists($username) +{ + $result = exec_stmt('SELECT username FROM user WHERE username = ?', 's', $username)->fetch_assoc(); + + if (isset($result['username'])) + return true; + else + return false; +} + +function login($username, $password) +{ + $user = exec_stmt('SELECT id FROM user WHERE username = ? AND password = ?', 'ss', $username, $password)->fetch_assoc(); + + if (!isset($user['id'])) + return false; + + $_SESSION['id'] = $user['id']; + return true; +} + +function signup($username, $password, $verify_password) +{ + echo 'test'; + if (username_exists($username)) + return false; + + echo 'username=' . $username; + + if ($password != $verify_password) + return false; + + $user_id = exec_stmt('INSERT INTO user (username, password) VALUES (?, ?)', 'ss', $username, $password); + + echo 'user_id=' . $user_id; + + if (!isset($user_id)) + return false; + + $_SESSION['id'] = $user_id; + return true; +} diff --git a/catalog/head.php b/catalog/head.php deleted file mode 100755 index c9e996d..0000000 --- a/catalog/head.php +++ /dev/null @@ -1,10 +0,0 @@ - - E-Commerce - - - EOL; - -echo $head; diff --git a/catalog/img/1.jpg b/catalog/img/1.jpg new file mode 100644 index 0000000..5341bf9 Binary files /dev/null and b/catalog/img/1.jpg differ diff --git a/catalog/img/10.jpg b/catalog/img/10.jpg new file mode 100644 index 0000000..0cdb8b6 Binary files /dev/null and b/catalog/img/10.jpg differ diff --git a/catalog/img/11.jpg b/catalog/img/11.jpg new file mode 100644 index 0000000..3bf7ecd Binary files /dev/null and b/catalog/img/11.jpg differ diff --git a/catalog/img/12.jpg b/catalog/img/12.jpg new file mode 100644 index 0000000..3227335 Binary files /dev/null and b/catalog/img/12.jpg differ diff --git a/catalog/img/13.jpg b/catalog/img/13.jpg new file mode 100644 index 0000000..1d511a6 Binary files /dev/null and b/catalog/img/13.jpg differ diff --git a/catalog/img/14.jpg b/catalog/img/14.jpg new file mode 100644 index 0000000..5a1ca2e Binary files /dev/null and b/catalog/img/14.jpg differ diff --git a/catalog/img/15.jpg b/catalog/img/15.jpg new file mode 100644 index 0000000..5cf6b7a Binary files /dev/null and b/catalog/img/15.jpg differ diff --git a/catalog/img/16.jpg b/catalog/img/16.jpg new file mode 100644 index 0000000..70d0f65 Binary files /dev/null and b/catalog/img/16.jpg differ diff --git a/catalog/img/17.jpg b/catalog/img/17.jpg new file mode 100644 index 0000000..8be7c09 Binary files /dev/null and b/catalog/img/17.jpg differ diff --git a/catalog/img/18.jpg b/catalog/img/18.jpg new file mode 100644 index 0000000..fb2df38 Binary files /dev/null and b/catalog/img/18.jpg differ diff --git a/catalog/img/19.jpg b/catalog/img/19.jpg new file mode 100644 index 0000000..f42e05c Binary files /dev/null and b/catalog/img/19.jpg differ diff --git a/catalog/img/2.jpg b/catalog/img/2.jpg new file mode 100644 index 0000000..9540512 Binary files /dev/null and b/catalog/img/2.jpg differ diff --git a/catalog/img/20.jpg b/catalog/img/20.jpg new file mode 100644 index 0000000..444fce7 Binary files /dev/null and b/catalog/img/20.jpg differ diff --git a/catalog/img/3.jpg b/catalog/img/3.jpg new file mode 100644 index 0000000..26b8a2f Binary files /dev/null and b/catalog/img/3.jpg differ diff --git a/catalog/img/4.jpg b/catalog/img/4.jpg new file mode 100644 index 0000000..f9f42cc Binary files /dev/null and b/catalog/img/4.jpg differ diff --git a/catalog/img/5.jpg b/catalog/img/5.jpg new file mode 100644 index 0000000..958c6ee Binary files /dev/null and b/catalog/img/5.jpg differ diff --git a/catalog/img/6.jpg b/catalog/img/6.jpg new file mode 100644 index 0000000..8865aed Binary files /dev/null and b/catalog/img/6.jpg differ diff --git a/catalog/img/7.jpg b/catalog/img/7.jpg new file mode 100644 index 0000000..cf41115 Binary files /dev/null and b/catalog/img/7.jpg differ diff --git a/catalog/img/8.jpg b/catalog/img/8.jpg new file mode 100644 index 0000000..252d742 Binary files /dev/null and b/catalog/img/8.jpg differ diff --git a/catalog/img/9.jpg b/catalog/img/9.jpg new file mode 100644 index 0000000..9ad7e30 Binary files /dev/null and b/catalog/img/9.jpg differ diff --git a/catalog/img/anvil.jpg b/catalog/img/anvil.jpg new file mode 100644 index 0000000..d48b0b6 Binary files /dev/null and b/catalog/img/anvil.jpg differ diff --git a/catalog/img/atom_rearranger.jpg b/catalog/img/atom_rearranger.jpg new file mode 100644 index 0000000..be7f203 Binary files /dev/null and b/catalog/img/atom_rearranger.jpg differ diff --git a/catalog/img/axle_grease.jpg b/catalog/img/axle_grease.jpg new file mode 100644 index 0000000..b8b1289 Binary files /dev/null and b/catalog/img/axle_grease.jpg differ diff --git a/catalog/img/bed_springs.jpeg b/catalog/img/bed_springs.jpeg new file mode 100644 index 0000000..6b68be2 Binary files /dev/null and b/catalog/img/bed_springs.jpeg differ diff --git a/catalog/img/bird_seed.jpg b/catalog/img/bird_seed.jpg new file mode 100644 index 0000000..2f3f9ea Binary files /dev/null and b/catalog/img/bird_seed.jpg differ diff --git a/catalog/img/blasting_powder.JPG b/catalog/img/blasting_powder.JPG new file mode 100644 index 0000000..f7519b0 Binary files /dev/null and b/catalog/img/blasting_powder.JPG differ diff --git a/catalog/img/cork.jpg b/catalog/img/cork.jpg new file mode 100644 index 0000000..77b70bf Binary files /dev/null and b/catalog/img/cork.jpg differ diff --git a/catalog/img/disintegration_pistol.png b/catalog/img/disintegration_pistol.png new file mode 100644 index 0000000..52ae56b Binary files /dev/null and b/catalog/img/disintegration_pistol.png differ diff --git a/catalog/img/earthquake_pills.jpg b/catalog/img/earthquake_pills.jpg new file mode 100644 index 0000000..9660461 Binary files /dev/null and b/catalog/img/earthquake_pills.jpg differ diff --git a/catalog/img/female_roadrunner_costume.jpg b/catalog/img/female_roadrunner_costume.jpg new file mode 100644 index 0000000..fc68ee5 Binary files /dev/null and b/catalog/img/female_roadrunner_costume.jpg differ diff --git a/catalog/img/giant_rubber_band.jpg b/catalog/img/giant_rubber_band.jpg new file mode 100644 index 0000000..f16e230 Binary files /dev/null and b/catalog/img/giant_rubber_band.jpg differ diff --git a/catalog/img/instant_girl.jpg b/catalog/img/instant_girl.jpg new file mode 100644 index 0000000..26a32e3 Binary files /dev/null and b/catalog/img/instant_girl.jpg differ diff --git a/catalog/img/iron_carrot.jpeg b/catalog/img/iron_carrot.jpeg new file mode 100644 index 0000000..d4f35f3 Binary files /dev/null and b/catalog/img/iron_carrot.jpeg differ diff --git a/catalog/img/jet_propelled_unicycle.jpg b/catalog/img/jet_propelled_unicycle.jpg new file mode 100644 index 0000000..b0b70b9 Binary files /dev/null and b/catalog/img/jet_propelled_unicycle.jpg differ diff --git a/catalog/img/outboard_motor.jpg b/catalog/img/outboard_motor.jpg new file mode 100644 index 0000000..041a61c Binary files /dev/null and b/catalog/img/outboard_motor.jpg differ diff --git a/catalog/img/railroad_track.jpeg b/catalog/img/railroad_track.jpeg new file mode 100644 index 0000000..a4334e1 Binary files /dev/null and b/catalog/img/railroad_track.jpeg differ diff --git a/catalog/img/rocket_sled.jpg b/catalog/img/rocket_sled.jpg new file mode 100644 index 0000000..c6100ed Binary files /dev/null and b/catalog/img/rocket_sled.jpg differ diff --git a/catalog/img/super_outfit.jpeg b/catalog/img/super_outfit.jpeg new file mode 100644 index 0000000..716deff Binary files /dev/null and b/catalog/img/super_outfit.jpeg differ diff --git a/catalog/img/time_space_gun.jpeg b/catalog/img/time_space_gun.jpeg new file mode 100644 index 0000000..c560ad9 Binary files /dev/null and b/catalog/img/time_space_gun.jpeg differ diff --git a/catalog/img/xray.jpeg b/catalog/img/xray.jpeg new file mode 100644 index 0000000..178d827 Binary files /dev/null and b/catalog/img/xray.jpeg differ diff --git a/catalog/index.php b/catalog/index.php index e0e6bf3..341d865 100755 --- a/catalog/index.php +++ b/catalog/index.php @@ -1,9 +1,20 @@ '; -echo ''; -include('head.php'); +include_once 'functions/init.php'; +require_once 'functions/user.php'; -echo ''; -include('nav.php'); -echo ''; -echo ''; +if (isset($_POST['username']) && isset($_POST['password'])) { + if (login($_POST['username'], $_POST['password'])) + header('Location: catalog.php'); + else + echo '

Username and/or password are incorrect!

'; +} + +include_once 'components/head.php'; +include_once 'components/user/login.php'; + +if (isset($_SESSION['id'])) { + echo '

Welcome to the store

'; +} else + echo login_form(); + +include_once 'components/foot.php'; diff --git a/catalog/js/create-account.js b/catalog/js/create-account.js new file mode 100755 index 0000000..531c632 --- /dev/null +++ b/catalog/js/create-account.js @@ -0,0 +1,65 @@ +const username_field = document.querySelector('#username'); +const password_field = document.querySelector('#password'); +const v_password_field = document.querySelector('#v_password'); +const submit_button = document.querySelector('input[type="submit"]'); + +const err_username = document.querySelector('#err_username'); +const err_match = document.querySelector('#err_match'); +const err_length = document.querySelector('#err_length'); +const err_num = document.querySelector('#err_num'); + +function handle_input() { + const password = password_field.value; + const v_password = v_password_field.value; + if (password != v_password && v_password != '') + err_match.innerText = 'Passwords do not match.'; + else + err_match.innerText = ''; + + + if (password.length < 8) + err_length.innerText = 'Password must be at least 8 characters long.'; + else + err_length.innerText = ''; + + const num_regex = /\d/; + if (!num_regex.test(password)) + err_num.innerText = 'Password must have at least 1 digit.'; + else + err_num.innerText = ''; + + if (err_match.innerText == '' && err_length.innerText == '' && err_num.innerText == '' && err_username == '' && v_password != '') + submit_button.disabled = false; + else + submit_button.disabled = true; +} + +function handle_username() { + const username = username_field.value; + + fetch('functions/user.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: 'form_id=create-account&username=' + username, + }) + .then(response => { + if (!response.ok) { + console.log('Failed to check if username exists!'); + } + + return response.json(); // Parse response body as JSON + }) + .then(data => { + if (data['exists'] == 'True') + err_username.innerText = 'Username is taken.'; + else + err_username.innerText = ''; + }); +} + +username_field.addEventListener('blur', handle_username); +password_field.addEventListener('input', handle_input); +v_password_field.addEventListener('input', handle_input); +submit_button.disabled = true; diff --git a/catalog/js/login-modal.js b/catalog/js/login-modal.js new file mode 100644 index 0000000..e48ffac --- /dev/null +++ b/catalog/js/login-modal.js @@ -0,0 +1,31 @@ +const add_to_cart = document.querySelector('input[type="submit"]'); + +const modal = document.querySelector('.modal'); +const username = document.querySelector('#username'); +const password = document.querySelector('#password'); +const login_button = document.querySelector('#login_submit'); + + +add_to_cart.addEventListener('click', (e) => { + e.preventDefault(); + + if (modal.classList[0] === "fade-in") { + modal.classList.remove("fade-in"); + modal.classList.add("fade-out"); + } else { + modal.classList.remove("fade-out"); + modal.classList.add("fade-in"); + } + + + modal.addEventListener('click', () => { + if (modal.classList[0] === "fade-in") { + modal.classList.remove("fade-in"); + modal.classList.add("fade-out"); + } else { + modal.classList.remove("fade-out"); + modal.classList.add("fade-in"); + } + }) + +}); diff --git a/catalog/logout.php b/catalog/logout.php old mode 100755 new mode 100644 index e69de29..b4d1703 --- a/catalog/logout.php +++ b/catalog/logout.php @@ -0,0 +1,7 @@ + - - - EOL; - -echo $nav; diff --git a/catalog/product.php b/catalog/product.php index e69de29..367d0f4 100755 --- a/catalog/product.php +++ b/catalog/product.php @@ -0,0 +1,21 @@ +'; +$product = fetch_product($_GET['id']); +echo product_page($product); +echo ''; + +require_once 'components/foot.php'; diff --git a/catalog/scripts/init.sh b/catalog/scripts/init.sh new file mode 100755 index 0000000..e7d18cb --- /dev/null +++ b/catalog/scripts/init.sh @@ -0,0 +1 @@ +mariadb -u root -p < setup.sql diff --git a/catalog/scripts/setup.sql b/catalog/scripts/setup.sql new file mode 100644 index 0000000..18399c2 --- /dev/null +++ b/catalog/scripts/setup.sql @@ -0,0 +1,43 @@ +CREATE DATABASE IF NOT EXISTS catalog; +USE catalog; + +CREATE TABLE IF NOT EXISTS user + ( + id INT PRIMARY KEY AUTO_INCREMENT, + username VARCHAR(50) NOT NULL UNIQUE, + password VARCHAR(1024) NOT NULL, + login_token VARCHAR(1024) NOT NULL UNIQUE, + salt VARCHAR(256) NOT NULL, + INDEX (login_token) + ); + +CREATE TABLE IF NOT EXISTS product + ( + id INT PRIMARY KEY AUTO_INCREMENT, + name VARCHAR(50) NOT NULL UNIQUE, + description VARCHAR(500) NOT NULL, + image VARCHAR(100), + price FLOAT NOT NULL + ); + +INSERT INTO product (name, description, image, price) VALUES + ("Anvil", "A heavy steel block used for hammering and shaping metal.", "anvil.jpg", 75.00), + ("Axle Grease", "A thick lubricant used to reduce friction in axles and other moving parts.", "axle_grease.jpg", 8.50), + ("Atom Re-Arranger", "A device of questionable scientific validity that purports to rearrange atoms.", "atom_rearranger.jpg", 499.99), + ("Bed Springs", "Coiled metal springs used in mattresses and furniture for support.", "bed_springs.jpeg", 35.75), + ("Bird Seed", "A mixture of seeds formulated as food for pet birds.", "bird_seed.jpg", 12.20), + ("Blasting Powder", "An explosive material used for demolition and mining. Handle with extreme caution!", "blasting_powder.JPG", 150.00), + ("Cork", "The bark of the cork oak tree, often used for bottle stoppers and insulation.", "cork.jpg", 2.50), + ("Disintegration Pistol", "A fictional weapon capable of breaking down matter at a molecular level.", "disintegration_pistol.png", 299.00), + ("Earthquake Pills", "Pills that supposedly induce seismic activity. Effects not guaranteed.", "earthquake_pills.jpg", 55.00), + ("Female Roadrunner costume", "A feathered costume designed to resemble a female roadrunner.", "roadrunner_costume_female.jpg", 62.99), + ("Giant Rubber Band", "An oversized elastic band, useful for large-scale stretching or launching.", "giant_rubber_band.jpg", 19.95), + ("Instant Girl", "A product that claims to instantly create a companion. Results may vary significantly.", "instant_girl.jpg", 78.30), + ("Iron Carrot", "A carrot made of iron. Purpose unclear.", "iron_carrot.jpeg", 22.50), + ("Jet Propelled Unicycle", "A single-wheeled vehicle powered by a jet engine. For experienced riders only.", "jet_propelled_unicycle.jpg", 599.00), + ("Out-Board Motor", "A detachable motor mounted on the outside of a boat's transom.", "outboard_motor.jpg", 210.00), + ("Railroad Track", "A section of steel rail used for train tracks.", "railroad_track.jpeg", 315.50), + ("Rocket Sled", "A sled propelled by a rocket engine, designed for high-speed travel on rails.", "rocket_sled.jpg", 850.00), + ("Super Outfit", "A costume that allegedly grants the wearer extraordinary abilities. Claims not verified.", "super_outfit.jpeg", 95.00), + ("Time Space Gun", "A fictional device that manipulates the fabric of spacetime. Use with caution.", "time_space_gun.jpeg", 675.00), + ("X-Ray", "An electromagnetic radiation with high energy, often used for medical imaging.", "x_ray.jpeg", 1.00);