]> source.dussan.org Git - nextcloud-server.git/commitdiff
Merge pull request #15404 from Crote/occ-password-from-env
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 9 Apr 2015 22:08:40 +0000 (00:08 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 9 Apr 2015 22:08:40 +0000 (00:08 +0200)
Add password input from env variable for occ user:{add, resetpassword}

1  2 
core/command/user/add.php

index 1ae0ffbe2ad79ca2bcb58c44ada2eedaacebae16,a566ed2db7ad0247643fa5eac613fa6adc042ea9..60c70bf13dd2b1e963ac2eae87f0e607c0bc1496
@@@ -81,17 -81,36 +81,36 @@@ class Add extends Command 
                $uid = $input->getArgument('uid');
                if ($this->userManager->userExists($uid)) {
                        $output->writeln('<error>The user "' . $uid . '" already exists.</error>');
 -                      return;
 +                      return 1;
                }
  
-               $password = $input->getOption('password');
-               while (!$password) {
-                       $question = new Question('Please enter a non-empty password:');
-                       $question->setHidden(true);
-                       $question->setHiddenFallback(false);
+               if ($input->getOption('password-from-env')) {
+                       $password = getenv('OC_PASS');
+                       if (!$password) {
+                               $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
+                               return 1;
+                       }
+               } elseif ($input->isInteractive()) {
+                       /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
+                       $dialog = $this->getHelperSet()->get('dialog');
+                       $password = $dialog->askHiddenResponse(
+                               $output,
+                               '<question>Enter password: </question>',
+                               false
+                       );
+                       $confirm = $dialog->askHiddenResponse(
+                               $output,
+                               '<question>Confirm password: </question>',
+                               false
+                       );
  
-                       $helper = $this->getHelper('question');
-                       $password = $helper->ask($input, $output, $question);
+                       if ($password !== $confirm) {
+                               $output->writeln("<error>Passwords did not match!</error>");
+                               return 1;
+                       }
+               } else {
+                       $output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>");
+                       return 1;
                }
  
                $user = $this->userManager->createUser(