public function create() { if (!Sessions_helper::userIsAdmin()) { $this->redirect_to(); } if (count($_POST) > 0) { switch ($_POST['product_catagory']) { case 'book': $this->explodeCreatorList('author'); break; case 'film': $this->explodeCreatorList('director'); break; } require_once '../app/models/' . ucfirst($_POST['product_catagory']) . '.php'; $product = new $_POST['product_catagory'](); $productId = $product->build($_POST['product_catagory']); if ($productId != 0) { $this->redirect_to('products/item/' . $productId); break; } } else { $product = new Product(); } $view = new View('products/create', ['header' => false, 'footer' => false]); $view->set_title('Add product'); $view->pass_data('product', $product); $view->load_page(); }
public function __construct() { require_once '../app/helpers/Checkout_helper.php'; session_start(); if (!Sessions_helper::logged_in()) { $this->redirect_to('sessions/login?redirect=checkout'); break; } elseif (!isset($_SESSION['checkout'])) { $_SESSION['checkout'] = []; $this->redirect_to('checkout/index'); break; } if ($_SESSION['cart'] == null) { $this->redirect_to('carts'); } //Redirect to earlier page if previous information is missing if (!isset($_SESSION['redirecting'])) { $stages = ['address', 'deliveryMethod', 'paymentMethod']; foreach ($stages as $stage) { if ($_SESSION['checkout']['properties'][$stage] == null) { $_SESSION['redirecting'] = true; $this->redirect_to('checkout/' . $stage); break; } } } else { unset($_SESSION['redirecting']); } }
public function userIsAdmin() { if (Sessions_helper::currentUser()['admin'] == '1') { return true; } else { return false; } }
protected function mustBeLoggedIn($url = false) { if (!Sessions_helper::logged_in()) { if ($url == false) { $url = $_GET['url']; } $this->redirect_to('sessions/login?redirect=' . $url); } }
public function removeItem() { if (Sessions_helper::logged_in()) { require_once '../app/models/Cart.php'; $cart = new Cart(); $cart->removeItem($_POST['productVersionId']); } else { if (array_key_exists($_POST['productVersionId'], $_SESSION['cart'])) { unset($_SESSION['cart'][$_POST['productVersionId']]); if (count($_SESSION['cart']) == 0) { unset($_SESSION['cart']); } } } $this->redirect_to('carts'); }
public function newUser() { $user = new User(); if (isset($_POST['first_name'])) { $user->assignProperties($_POST); if ($user->saveToDb('INSERT INTO', 'users', $user->properties)) { Sessions_helper::login(); if (array_key_exists('redirect', $_POST)) { $this->redirect_to($_POST['redirect']); } else { $this->redirect_to('home/index'); } } } $view = new View('layouts/register_login', ['header' => false, 'footer' => false]); $view->set_title('Create account'); $view->pass_data('user', $user); $view->load_page(); }
public function login($error = false) { if (isset($_POST['email']) && isset($_POST['password']) && $_POST['email'] != '' && $_POST['password'] != '') { if (Sessions_helper::login()) { if (array_key_exists('redirect', $_POST)) { $this->redirect_to($_POST['redirect']); } else { $this->redirect_to('home/index'); } } else { $_POST['email'] = ''; $_POST['password'] = ''; $this->login(true); } } $view = new View('layouts/register_login', ['header' => false, 'footer' => false]); $view->set_title('Login'); $view->pass_data('loginError', $error); $view->load_page(); }
<div class="account-page"> <h1>Hi, <?php echo Sessions_helper::currentUser()['first_name']; ?> </h1> <ul> <li><a href='<?php echo $this->rootPath(); ?> account/orders'> <div><?php echo $this->image_tag('icons/purchase_history.svg', ['height' => 200]); ?> <br>Your Orders</div> </a></li> <li><a href='<?php echo $this->rootPath(); ?> wish_lists/show/1'> <div><?php echo $this->image_tag('icons/wish_list.svg', ['height' => 200]); ?> <br>Wish Lists</div> </a></li> <li><a href='<?php echo $this->rootPath(); ?> account/paymentmethods'> <div><?php echo $this->image_tag('icons/payment_methods.svg', ['height' => 200]); ?>
?> Hello, <?php echo Sessions_helper::currentUser()['first_name']; ?> ! <span class="logout"><?php $this->link_to('sessions/logout', 'Logout'); ?> </span> <?php } else { ?> Hello. <?php $this->link_to('sessions/login', 'Sign in'); ?> or <?php $this->link_to('users/newuser', 'register'); ?> . <?php } ?> </span> <?php if (Sessions_helper::userIsAdmin()) { echo "<a href='" . $this->rootPath() . "products/create' class='admin-link'>Add product</a>"; } ?> </div> </div>