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), '')); }
public function testUpdatePassword() { $admin = AdminQuery::create()->findOne(); $adminEvent = new AdministratorUpdatePasswordEvent($admin); $adminEvent->setPassword('toto'); $actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider); $actionAdmin->updatePassword($adminEvent); $updatedAdmin = $adminEvent->getAdmin(); $this->assertInstanceOf("Thelia\\Model\\Admin", $updatedAdmin); $this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword())); }
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"); }