Ejemplo n.º 1
0
 /**
  * @param AdministratorEvent $event
  */
 public function delete(AdministratorEvent $event)
 {
     if (null !== ($administrator = AdminQuery::create()->findPk($event->getId()))) {
         $administrator->delete();
         $event->setAdministrator($administrator);
     }
 }
Ejemplo n.º 2
0
 public function verifyExistingLogin($value, ExecutionContextInterface $context)
 {
     $administrator = AdminQuery::create()->findOneByLogin($value);
     if ($administrator !== null) {
         $context->addViolation("This login already exists");
     }
 }
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     $administrator = AdminQuery::create()->findOneByEmail($value);
     if (null !== $administrator && $administrator->getId() != $data['id']) {
         $context->addViolation($this->translator->trans("An administrator with thie email address already exists"));
     }
 }
 public function verifyExistingLogin($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     $administrator = AdminQuery::create()->findOneByLogin($value);
     if ($administrator !== null && $administrator->getId() != $data['id']) {
         $context->addViolation(Translator::getInstance()->trans("This login already exists"));
     }
 }
Ejemplo n.º 5
0
 public function getUser($key)
 {
     // Try with login name
     $admin = AdminQuery::create()->filterByLogin($key, Criteria::EQUAL)->findOne();
     // Try with email address
     if (null == $admin && !empty($key)) {
         $admin = AdminQuery::create()->filterByEmail($key, Criteria::EQUAL)->findOne();
     }
     return $admin;
 }
Ejemplo n.º 6
0
 public function testUpdatePassword()
 {
     $admin = AdminQuery::create()->findOne();
     $adminEvent = new AdministratorUpdatePasswordEvent($admin);
     $adminEvent->setPassword('toto')->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $actionAdmin = new Administrator();
     $actionAdmin->updatePassword($adminEvent);
     $updatedAdmin = $adminEvent->getAdmin();
     $this->assertInstanceOf("Thelia\\Model\\Admin", $updatedAdmin);
     $this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument('login');
     if (null === ($admin = AdminQuery::create()->filterByLogin($login)->findOne())) {
         throw new \RuntimeException(sprintf('Admin with login %s does not exists', $login));
     }
     $password = $input->getOption('password') ?: Password::generateRandom();
     $event = new AdministratorUpdatePasswordEvent($admin);
     $event->setPassword($password);
     $this->getContainer()->get('event_dispatcher')->dispatch(TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD, $event);
     $output->writeln(array('', sprintf('<info>admin %s password updated</info>', $login), sprintf('<info>new password is : %s</info>', $password), ''));
 }
Ejemplo n.º 8
0
 public function buildModelCriteria()
 {
     $search = AdminQuery::create();
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $profile = $this->getProfile();
     if (null !== $profile) {
         $search->filterByProfileId($profile, Criteria::IN);
     }
     $search->orderByFirstname(Criteria::ASC);
     return $search;
 }
Ejemplo n.º 9
0
 public function getUser($dataArray)
 {
     return AdminQuery::create()->filterByLogin($dataArray['username'])->filterByRememberMeSerial($dataArray['serial'])->filterByRememberMeToken($dataArray['token'])->findOne();
 }
Ejemplo n.º 10
0
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     if (null !== ($administrator = AdminQuery::create()->findOneByEmail($value))) {
         $context->addViolation($this->translator->trans("An administrator with thie email address already exists"));
     }
 }
Ejemplo n.º 11
0
 public function getUser($key)
 {
     $admin = AdminQuery::create()->filterByLogin($key, Criteria::EQUAL)->findOne();
     return $admin;
 }
Ejemplo n.º 12
0
 protected function enterEmail($dialog, $output)
 {
     return $email = $dialog->askAndValidate($output, $this->decorateInfo("Admin email or empty value : "), function ($answer) {
         $answer = trim($answer);
         if (!empty($answer) && !filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new \RuntimeException("Please enter an email or an empty value.");
         }
         if (AdminQuery::create()->findOneByEmail($answer)) {
             throw new \RuntimeException("An administrator with this email already exists.");
         }
         return !empty($answer) ? $answer : uniqid('CHANGE_ME_');
     });
 }
Ejemplo n.º 13
0
 protected function enterEmail(QuestionHelper $helper, InputInterface $input, OutputInterface $output)
 {
     $question = new Question($this->decorateInfo("Admin email or empty value : "));
     $question->setValidator(function ($answer) {
         $answer = trim($answer);
         if (!empty($answer) && !filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new \RuntimeException("Please enter an email or an empty value.");
         }
         if (AdminQuery::create()->findOneByEmail($answer)) {
             throw new \RuntimeException("An administrator with this email already exists.");
         }
         return !empty($answer) ? $answer : uniqid('CHANGE_ME_');
     });
     return $helper->ask($input, $output, $question);
 }
Ejemplo n.º 14
0
 /**
  * Performs an INSERT on the database, given a Admin or Criteria object.
  *
  * @param mixed               $criteria Criteria or Admin object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(AdminTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Admin object
     }
     if ($criteria->containsKey(AdminTableMap::ID) && $criteria->keyContainsValue(AdminTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AdminTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AdminQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
Ejemplo n.º 15
0
 public function passwordCreatedAction()
 {
     if (null !== ($response = $this->checkPasswordRecoveryEnabled()) || null !== ($response = $this->checkAdminLoggedIn())) {
         return $response;
     }
     $adminCreatePasswordForm = $this->createForm(AdminForm::ADMIN_CREATE_PASSWORD);
     try {
         $form = $this->validateForm($adminCreatePasswordForm, "post");
         $data = $form->getData();
         $token = $this->getSession()->get(self::ADMIN_TOKEN_SESSION_VAR_NAME);
         if (empty($token) || null === ($admin = AdminQuery::create()->findOneByPasswordRenewToken($token))) {
             throw new \Exception($this->getTranslator()->trans("An invalid token was provided, your password cannot be changed"));
         }
         $event = new AdministratorUpdatePasswordEvent($admin);
         $event->setPassword($data['password']);
         $this->dispatch(TheliaEvents::ADMINISTRATOR_UPDATEPASSWORD, $event);
         $this->getSession()->set(self::ADMIN_TOKEN_SESSION_VAR_NAME, null);
         return $this->generateSuccessRedirect($adminCreatePasswordForm);
     } catch (FormValidationException $ex) {
         // Validation problem
         $message = $this->createStandardFormValidationErrorMessage($ex);
     } catch (\Exception $ex) {
         // Log authentication failure
         AdminLog::append("admin", "ADMIN_CREATE_PASSWORD", $ex->getMessage(), $this->getRequest());
         $message = $ex->getMessage();
     }
     $this->setupFormErrorContext("Login process", $message, $adminCreatePasswordForm, $ex);
     return $this->render("create-password");
 }
Ejemplo n.º 16
0
 Model\FeatureProductQuery::create()->deleteAll();
 Model\AttributeCombinationQuery::create()->deleteAll();
 Model\FeatureQuery::create()->deleteAll();
 Model\FeatureI18nQuery::create()->deleteAll();
 Model\FeatureAvQuery::create()->deleteAll();
 Model\FeatureAvI18nQuery::create()->deleteAll();
 Model\AttributeQuery::create()->deleteAll();
 Model\AttributeI18nQuery::create()->deleteAll();
 Model\AttributeAvQuery::create()->deleteAll();
 Model\AttributeAvI18nQuery::create()->deleteAll();
 Model\CategoryQuery::create()->deleteAll();
 Model\CategoryI18nQuery::create()->deleteAll();
 Model\ProductQuery::create()->deleteAll();
 Model\ProductI18nQuery::create()->deleteAll();
 Model\CustomerQuery::create()->deleteAll();
 Model\AdminQuery::create()->deleteAll();
 Model\FolderQuery::create()->deleteAll();
 Model\FolderI18nQuery::create()->deleteAll();
 Model\ContentQuery::create()->deleteAll();
 Model\ContentI18nQuery::create()->deleteAll();
 Model\AccessoryQuery::create()->deleteAll();
 Model\ProductSaleElementsQuery::create()->deleteAll();
 Model\ProductPriceQuery::create()->deleteAll();
 Model\BrandQuery::create()->deleteAll();
 Model\BrandI18nQuery::create()->deleteAll();
 Model\ProductImageQuery::create()->deleteAll();
 Model\CategoryImageQuery::create()->deleteAll();
 Model\FolderImageQuery::create()->deleteAll();
 Model\ContentImageQuery::create()->deleteAll();
 Model\BrandImageQuery::create()->deleteAll();
 Model\ProductDocumentQuery::create()->deleteAll();
Ejemplo n.º 17
0
 public function testRenewPassword()
 {
     $admin = AdminQuery::create()->findOne();
     $admin->setPasswordRenewToken(null)->setEmail('*****@*****.**')->save();
     $adminEvent = new AdministratorEvent($admin);
     $actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
     $actionAdmin->createPassword($adminEvent);
     $updatedAdmin = $adminEvent->getAdministrator();
     $this->assertInstanceOf("Thelia\\Model\\Admin", $updatedAdmin);
     $this->assertNotEmpty($admin->getPasswordRenewToken());
 }
Ejemplo n.º 18
0
 /**
  * Returns the number of related Admin objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related Admin objects.
  * @throws PropelException
  */
 public function countAdmins(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collAdminsPartial && !$this->isNew();
     if (null === $this->collAdmins || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collAdmins) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getAdmins());
         }
         $query = ChildAdminQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByProfile($this)->count($con);
     }
     return count($this->collAdmins);
 }
Ejemplo n.º 19
0
 protected function getExistingObject()
 {
     return AdminQuery::create()->findOneById($this->getRequest()->get('administrator_id'));
 }
Ejemplo n.º 20
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Admin::setDeleted()
  * @see Admin::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(AdminTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAdminQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }