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)); }
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)); }
/** * Return Logged User * * @return UserEntity|null */ public static function getLoggedUser() { $loggedUserId = Session::get('logged_user'); if (!$loggedUserId) { return null; } $em = Project::getEntityManager(); $user = $em->get('App\\Entity\\UserEntity', intval($loggedUserId)); return $user; }
public function modelAction($brandId) { $models = Project::getEntityManager()->getAllBy('App\\Entity\\ModelAutoEntity', array('brand_id' => $brandId), array('orderBy' => 'name')); if (empty($models)) { return 0; } foreach ($models as $model) { echo '<option value="' . $model->getId() . '">' . $model->getName() . '</option>'; } }
public function indexAction() { $this->setTitle('Auto Parts Supply'); $products = Project::getEntityManager()->getAll('App\\Entity\\ProductEntity', array('limit' => 3, 'orderBy' => 'created', 'order' => 'DESC')); $this->renderTemplate('home.php', array('products' => $products)); }