Exemplo n.º 1
0
 /**
  * @covers PHPUnit::execute
  */
 public function testExecute_DoesNotChangePasswordIfEmpty()
 {
     $user = new User();
     $user->setHash(password_hash('testing', PASSWORD_DEFAULT));
     $user = $this->testedService->updateUser($user, 'Test', '*****@*****.**', '', 0);
     $this->assertTrue(password_verify('testing', $user->getHash()));
 }
Exemplo n.º 2
0
 /**
  * Delete a user.
  */
 public function delete($userId)
 {
     $this->requireAdmin();
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException(Lang::get('user_n_not_found', $userId));
     }
     $this->userService->deleteUser($user);
     header('Location: ' . PHPCI_URL . 'user');
     die;
 }
Exemplo n.º 3
0
 /**
  * Delete a user.
  */
 public function delete($userId)
 {
     $this->requireAdmin();
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException(Lang::get('user_n_not_found', $userId));
     }
     $this->userService->deleteUser($user);
     $response = new b8\Http\Response\RedirectResponse();
     $response->setHeader('Location', PHPCI_URL . 'user');
     return $response;
 }
Exemplo n.º 4
0
 /**
  * Creates an admin user in the existing PHPCI database
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userStore = Factory::getStore('User');
     $userService = new UserService($userStore);
     require PHPCI_DIR . 'bootstrap.php';
     // Try to create a user account:
     $adminEmail = $this->ask(Lang::get('enter_email'), true, FILTER_VALIDATE_EMAIL);
     if (empty($adminEmail)) {
         return;
     }
     $adminPass = $this->ask(Lang::get('enter_pass'));
     $adminName = $this->ask(Lang::get('enter_name'));
     try {
         $userService->createUser($adminName, $adminEmail, $adminPass, 1);
         print Lang::get('user_created') . PHP_EOL;
     } catch (\Exception $ex) {
         print Lang::get('failed_to_create') . PHP_EOL;
         print $ex->getMessage();
         print PHP_EOL;
     }
 }
Exemplo n.º 5
0
 /**
  * Creates an admin user in the existing PHPCI database
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userStore = Factory::getStore('User');
     $userService = new UserService($userStore);
     require PHPCI_DIR . 'bootstrap.php';
     // Try to create a user account:
     $adminEmail = $this->ask('Admin email address: ', true, FILTER_VALIDATE_EMAIL);
     if (empty($adminEmail)) {
         return;
     }
     $adminPass = $this->ask('Admin password: '******'Admin name: ');
     try {
         $userService->createUser($adminName, $adminEmail, $adminPass, 1);
         print 'User account created!' . PHP_EOL;
     } catch (\Exception $ex) {
         print 'There was a problem creating your account. :(' . PHP_EOL;
         print $ex->getMessage();
         print PHP_EOL;
     }
 }
Exemplo n.º 6
0
 /**
  * Delete a user.
  */
 public function delete($userId)
 {
     if (!$_SESSION['user']->getIsAdmin()) {
         throw new ForbiddenException('You do not have permission to do that.');
     }
     $user = $this->userStore->getById($userId);
     if (empty($user)) {
         throw new NotFoundException('User with ID: ' . $userId . ' does not exist.');
     }
     $this->userService->deleteUser($user);
     header('Location: ' . PHPCI_URL . 'user');
     die;
 }
Exemplo n.º 7
0
 /**
  * Creates an admin user in the existing PHPCI database
  *
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $userService = new UserService($this->userStore);
     /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
     $dialog = $this->getHelperSet()->get('dialog');
     // Function to validate mail address.
     $mailValidator = function ($answer) {
         if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new \InvalidArgumentException(Lang::get('must_be_valid_email'));
         }
         return $answer;
     };
     $adminEmail = $dialog->askAndValidate($output, Lang::get('enter_email'), $mailValidator, false);
     $adminName = $dialog->ask($output, Lang::get('enter_name'));
     $adminPass = $dialog->askHiddenResponse($output, Lang::get('enter_password'));
     try {
         $userService->createUser($adminName, $adminEmail, $adminPass, true);
         $output->writeln(Lang::get('user_created'));
     } catch (\Exception $e) {
         $output->writeln(sprintf('<error>%s</error>', Lang::get('failed_to_create')));
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
 }
Exemplo n.º 8
0
 /**
  * Create admin user using information loaded before.
  *
  * @param array $admin
  * @param OutputInterface $output
  */
 protected function createAdminUser($admin, $output)
 {
     try {
         $this->reloadConfig();
         $userStore = Factory::getStore('User');
         $userService = new UserService($userStore);
         $userService->createUser($admin['name'], $admin['mail'], $admin['pass'], 1);
         $output->writeln('<info>' . Lang::get('user_created') . '</info>');
     } catch (\Exception $ex) {
         $output->writeln('<error>' . Lang::get('failed_to_create') . '</error>');
         $output->writeln('<error>' . $ex->getMessage() . '</error>');
     }
 }
Exemplo n.º 9
0
 /**
  * @param OutputInterface $output
  * @param DialogHelper    $dialog
  */
 protected function createAdminUser(OutputInterface $output, DialogHelper $dialog)
 {
     // Try to create a user account:
     $adminEmail = $dialog->askAndValidate($output, 'Your email address: ', function ($answer) {
         if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new Exception('Must be a valid email address.');
         }
         return $answer;
     }, false);
     $adminPass = $dialog->askHiddenResponse($output, 'Enter your desired admin password: '******'Enter your name: ');
     try {
         $this->reloadConfig();
         $userStore = Factory::getStore('User');
         $userService = new UserService($userStore);
         $userService->createUser($adminName, $adminEmail, $adminPass, 1);
         $output->writeln('<info>User account created!</info>');
     } catch (\Exception $ex) {
         $output->writeln('<error>PHPCI failed to create your admin account.</error>');
         $output->writeln('<error>' . $ex->getMessage() . '</error>');
         die;
     }
 }