public function registerAction() { $this->setTitle('Inregistrare - Auto Parts Supply'); $error = ''; if (isset($_POST['email']) && isset($_POST['password']) && isset($_POST['name'])) { $email = $_POST['email']; $name = $_POST['name']; $password = $_POST['password']; $repassword = $_POST['repassword']; if ($email && $name && $password && $repassword) { if ($password != $repassword) { $error = 'Parolele nu sunt egale.'; } else { $em = Project::getEntityManager(); $created = new \DateTime(); $entity = $em->insert('App\\Entity\\UserEntity', array('name' => $name, 'email' => $email, 'password' => Security::generatePassword($password), 'status' => 1, 'created' => $created->format('Y-m-d H:i:s'), 'updated' => $created->format('Y-m-d H:i:s'))); if (!$entity) { $error = 'A fost o eroare in momentul inregistrari, te rugam incearca dinou.'; } else { $this->redirectTo('security/login'); } } } else { $error = 'Introdu valori valide.'; } } $this->renderTemplate('user/register.php', array('error' => $error)); }
public function createAction() { $this->setTitle('Create Product - Auto Parts Supply'); $error = ''; if (isset($_POST['name'])) { $name = $_POST['name']; if ($name) { $description = isset($_POST['description']) ? $_POST['description'] : ''; $stock = isset($_POST['stock']) ? $_POST['stock'] : 0; $price = isset($_POST['price']) ? $_POST['price'] : 0; $created = new \DateTime(); $user = Security::getLoggedUser(); $data = array('name' => $name, 'description' => $description, 'price' => $price, 'stock' => $stock, 'user_id' => $user->getId(), 'status' => 1, 'created' => $created->format('Y-m-d H:i:s'), 'updated' => $created->format('Y-m-d H:i:s')); $brandId = isset($_POST['brand']) && $_POST['brand'] ? intval($_POST['brand']) : null; if ($brandId) { $data['brand_id'] = $brandId; } $modelId = isset($_POST['model']) && $_POST['model'] ? intval($_POST['model']) : null; if ($modelId) { $data['model_id'] = $modelId; } $product = Project::getEntityManager()->insert('App\\Entity\\ProductEntity', $data); if (!$product) { $error = 'A fost o eroare in momentul crearii produsului, te rugam incearca dinou.'; } } else { $error = 'Numele este obligatoriu!'; } } $brands = Project::getEntityManager()->getAll('App\\Entity\\BrandAutoEntity'); $this->renderTemplate('product/create.php', array('brands' => $brands, 'error' => $error)); }
public function loginAction() { $this->setTitle('Conectare - Auto Parts Supply'); $error = ''; $isAlreadyLogged = Session::has('logged_user'); if (!$isAlreadyLogged && isset($_POST['email']) && isset($_POST['password'])) { $email = $_POST['email']; $password = $_POST['password']; if ($email && $password) { $em = Project::getEntityManager(); $user = $em->getOneBy('App\\Entity\\UserEntity', array('email' => $email)); if ($user && Security::checkPasswordForUser($password, $user)) { Session::set('logged_user', $user->getId()); $this->redirectTo(''); } if (!$user) { $error = 'Email-ul nu este valid.'; } if ($user && !Security::checkPasswordForUser($password, $user)) { $error = 'Parola nu este valida pentru acest email, te rugam incearca dinou.'; } } else { $error = 'Introdu te rog un email si o parola.'; } } elseif ($isAlreadyLogged) { throw new \Exception('A user is already logged'); } $this->renderTemplate('security/login.php', array('error' => $error)); }
<?php $this->renderTemplate('global/head.php'); ?> <div class="page_container"> <?php $this->renderTemplate('global/header.php'); ?> <?php if (\App\Lib\Security::isLoggedUser()) { ?> <div class="product-form"> <h3>Creare Produs</h3> <?php if (isset($error) && $error) { ?> <div class="error"> <?php echo $error; ?> </div> <?php } ?> <form action="<?php echo \App\Project::getUrl('product/create'); ?> " method="post">
</div> <div class="menu_link"> <form class="search-form" action="<?php echo \App\Project::getUrl('product/search'); ?> " method="GET"> <input type="text" name="query" value="" placeholder="Cautare produse"> <button type="submit"><i class="glyphicon glyphicon-search" aria-hidden="true"></i></button> </form> </div> <div class="menu_link"> <?php if (\App\Lib\Security::isLoggedUser()) { ?> <?php $user = \App\Lib\Security::getLoggedUser(); ?> <a href="<?php echo \App\Project::getUrl('security/logout'); ?> ">Deconectare (<?php echo $user->getName(); ?> )</a> <?php } else { ?> <a href="<?php echo \App\Project::getUrl('security/login'); ?> ">Connectare</a>