Example #1
0
 public function updateUser(User $user, $name, $emailAddress, $password = null, $isAdmin = null)
 {
     $user->setName($name);
     $user->setEmail($emailAddress);
     if (!empty($password)) {
         $user->setHash(password_hash($password, PASSWORD_DEFAULT));
     }
     if (!is_null($isAdmin)) {
         $user->setIsAdmin($isAdmin ? 1 : 0);
     }
     return $this->store->save($user);
 }
Example #2
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 {
         $user = new User();
         $user->setEmail($adminEmail);
         $user->setName($adminName);
         $user->setIsAdmin(1);
         $user->setHash(password_hash($adminPass, PASSWORD_DEFAULT));
         $this->reloadConfig();
         $store = Factory::getStore('User');
         $store->save($user);
         $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;
     }
 }
Example #3
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()));
 }
Example #4
0
 /**
  * Add a user - handles both form and processing.
  */
 public function add()
 {
     if (!$_SESSION['user']->getIsAdmin()) {
         throw new ForbiddenException('You do not have permission to do that.');
     }
     $this->config->set('page_title', 'Add User');
     $method = $this->request->getMethod();
     if ($method == 'POST') {
         $values = $this->getParams();
     } else {
         $values = array();
     }
     $form = $this->userForm($values);
     if ($method != 'POST' || $method == 'POST' && !$form->validate()) {
         $view = new b8\View('UserForm');
         $view->type = 'add';
         $view->user = null;
         $view->form = $form;
         return $view->render();
     }
     $values = $form->getValues();
     $values['hash'] = password_hash($values['password'], PASSWORD_DEFAULT);
     $user = new User();
     $user->setValues($values);
     $user = $this->userStore->save($user);
     header('Location: ' . PHPCI_URL . 'user');
     die;
 }