From a8c19de4d35a0e08dd11566f912f0fdfe794f7cb Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Thu, 13 Feb 2020 18:22:54 +0100 Subject: [PATCH 1/7] PHRAS-2927_optimize-feedback-process_4.1 add route "lightbox/ajax/GET_ELEMENTS/{{basket_id}}/" to get counts of elements validated as "yes", "no" or "nul". Will allow front to display alert before submitting --- .../Phrasea/Controller/LightboxController.php | 45 +++++++++++++++++++ .../Phrasea/ControllerProvider/Lightbox.php | 5 +++ 2 files changed, 50 insertions(+) diff --git a/lib/Alchemy/Phrasea/Controller/LightboxController.php b/lib/Alchemy/Phrasea/Controller/LightboxController.php index 30d7c81f65..19c7378c1f 100644 --- a/lib/Alchemy/Phrasea/Controller/LightboxController.php +++ b/lib/Alchemy/Phrasea/Controller/LightboxController.php @@ -450,6 +450,51 @@ class LightboxController extends Controller return $this->app->json($data); } + /** + * @param Basket $basket + * @return Response + */ + public function ajaxGetElementsAction(Basket $basket) + { + $ret = [ + 'error' => false, + 'datas' => [ + 'counts' => [ + 'yes' => 0, + 'no' => 0, + 'nul' => 0, + 'total' => 0 + ] + ] + ]; + try { + if (!$basket->getValidation()) { + throw new Exception('There is no validation session attached to this basket'); + } + foreach ($basket->getElements() as $element) { + $vd = $element->getUserValidationDatas($this->getAuthenticatedUser()); + if($vd->getAgreement() === true) { + $ret['datas']['counts']['yes']++; + } + elseif($vd->getAgreement() === false) { + $ret['datas']['counts']['no']++; + } + elseif($vd->getAgreement() === null) { + $ret['datas']['counts']['nul']++; + } + $ret['datas']['counts']['total']++; + } + } + catch (Exception $e) { + $ret = [ + 'error' => true, + 'datas' => $e->getMessage() + ]; + } + + return $this->app->json($ret); + } + /** * @param Basket $basket * @throws Exception diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php index c1485b862c..7e18fff788 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Lightbox.php @@ -105,6 +105,11 @@ class Lightbox implements ControllerProviderInterface, ServiceProviderInterface ->assert('basket', '\d+') ; + $controllers->get('/ajax/GET_ELEMENTS/{basket}/', 'controller.lightbox:ajaxGetElementsAction') + ->bind('lightbox_ajax_get_elements') + ->assert('basket', '\d+') + ; + return $controllers; } From 3d4d3aed3639590ba9a6742d60395d0bc2d66a19 Mon Sep 17 00:00:00 2001 From: aynsix Date: Fri, 28 Feb 2020 18:31:29 +0300 Subject: [PATCH 2/7] update command user:password --- bin/console | 4 +- .../Command/User/UserPasswordCommand.php | 140 ++++++++++++++++++ .../Command/User/UserSetPasswordCommand.php | 79 ---------- 3 files changed, 142 insertions(+), 81 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php delete mode 100644 lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php diff --git a/bin/console b/bin/console index c973195ff6..ddff5c0565 100755 --- a/bin/console +++ b/bin/console @@ -49,7 +49,7 @@ use Alchemy\Phrasea\Command\Task\TaskStart; use Alchemy\Phrasea\Command\Task\TaskState; use Alchemy\Phrasea\Command\Task\TaskStop; use Alchemy\Phrasea\Command\User\UserCreateCommand; -use Alchemy\Phrasea\Command\User\UserSetPasswordCommand; +use Alchemy\Phrasea\Command\User\UserPasswordCommand; use Alchemy\Phrasea\Command\User\UserListCommand; use Alchemy\Phrasea\Command\UpgradeDBDatas; @@ -120,7 +120,7 @@ $cli->command(new CreateDataboxCommand('databox:create')); $cli->command(new UserCreateCommand('user:create')); -$cli->command(new UserSetPasswordCommand('user:set-password')); +$cli->command(new UserPasswordCommand('user:password')); $cli->command(new UserListCommand('user:list')); diff --git a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php new file mode 100644 index 0000000000..403d96f4ab --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php @@ -0,0 +1,140 @@ +setDescription('Set user password in Phraseanet') + ->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.') + ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate the password') + ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'The password') + ->addOption('send_mail_password', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if password and generate are not define') + ->addOption('password_hash', null, InputOption::VALUE_OPTIONAL, 'Define a password hashed, work only with password_nonce') + ->addOption('password_nonce', null, InputOption::VALUE_OPTIONAL, 'Define a password nonce, work only with password_hash') + ->addOption('get_hash', null, InputOption::VALUE_NONE, 'return the password hashed') + + ->setHelp(''); + + return $this; + } + + protected function doExecute(InputInterface $input, OutputInterface $output) + { + $dialog = $this->getHelperSet()->get('dialog'); + $userRepository = $this->container['repo.users']; + $userManipulator = $this->container['manipulator.user']; + + $user = $userRepository->find($input->getOption('user_id')); + $password = $input->getOption('password'); + $generate = $input->getOption('generate'); + $sendMailPassword = $input->getOption('send_mail_password'); + $getHash = $input->getOption('get_hash'); + $passwordHash = $input->getOption('password_hash'); + $passwordNonce = $input->getOption('password_nonce'); + + + if ($user === null) { + $output->writeln('Not found User.'); + return 0; + } + + if ($passwordHash && $passwordNonce) { + $user->setNonce($passwordNonce); + $user->setPassword($passwordHash); + $userManipulator->updateUser($user); + + $output->writeln('password set with hashed pass'); + + return 0; + } + + if ($generate) { + $password = $this->container['random.medium']->generateString(64); + } else { + if (!$password && $sendMailPassword) { + $this->sendPasswordSetupMail($user); + + return 0; + } elseif (!$password && !$sendMailPassword && ! $getHash) { + $output->writeln('choose one option to set a password!'); + + return 0; + } + } + + if ($password) { + do { + $continue = mb_strtolower($dialog->ask($output, 'Do you want really set password to this user? (y/N)', 'N')); + } while (!in_array($continue, ['y', 'n'])); + + if ($continue !== 'y') { + $output->writeln('Aborting !'); + + return; + } + + $userManipulator->setPassword($user,$password); + } + + if (($password || $generate || $getHash) && $user->getPassword()) { + $hash = [ + 'password' => $user->getPassword(), + 'nonce' => $user->getNonce() + ]; + + echo json_encode($hash); + } elseif (is_null($password)) { + $output->writeln('password undefined'); + } + + return 0; + } + + /** + * Send mail for renew password + * @param User $user + */ + private function sendPasswordSetupMail(User $user) + { + $this->setDelivererLocator(new LazyLocator($this->container, 'notification.deliverer')); + $receiver = Receiver::fromUser($user); + + $token = $this->container['manipulator.token']->createResetPasswordToken($user); + + $mail = MailRequestPasswordSetup::create($this->container, $receiver); + $servername = $this->container['conf']->get('servername'); + $mail->setButtonUrl('http://'.$servername.'/login/renew-password/?token='.$token->getValue()); + $mail->setLogin($user->getLogin()); + + $this->deliver($mail); + } + +} diff --git a/lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php deleted file mode 100644 index 963910db02..0000000000 --- a/lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php +++ /dev/null @@ -1,79 +0,0 @@ -setDescription('Set user password in Phraseanet') - ->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.') - ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate the password') - ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'The password') - ->setHelp(''); - - return $this; - } - - protected function doExecute(InputInterface $input, OutputInterface $output) - { - - $dialog = $this->getHelperSet()->get('dialog'); - $userRepository = $this->container['repo.users']; - $userManipulator = $this->container['manipulator.user']; - $user = $userRepository->find($input->getOption('user_id')); - $password = $input->getOption('password'); - $generate = $input->getOption('generate'); - - if ($user === null) { - $output->writeln('Not found User.'); - return 0; - } - - if ($generate) { - $password = $this->container['random.medium']->generateString(64); - } else { - if (!$password) { - $output->writeln('--password option not specified'); - return 0; - } - } - - do { - $continue = mb_strtolower($dialog->ask($output, 'Do you want really set password to this user? (y/N)', 'N')); - } while (!in_array($continue, ['y', 'n'])); - - if ($continue !== 'y') { - $output->writeln('Aborting !'); - - return; - } - - $userManipulator->setPassword($user,$password); - $output->writeln('New password: ' . $password . ''); - - return 0; - } - -} From 27e8cdd9d2b1864e927932e84ef7c1d95ddd27c4 Mon Sep 17 00:00:00 2001 From: Nicolas Maillat Date: Fri, 28 Feb 2020 16:52:26 +0100 Subject: [PATCH 3/7] update cmd help --- lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php index 403d96f4ab..c0197ee417 100644 --- a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php +++ b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php @@ -34,12 +34,12 @@ class UserPasswordCommand extends Command $this->setDescription('Set user password in Phraseanet') ->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.') - ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate the password') - ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'The password') - ->addOption('send_mail_password', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if password and generate are not define') + ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate and set with a random value') + ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Set the user password to the input value') + ->addOption('send_mail_password', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if --password or --generate are not define') ->addOption('password_hash', null, InputOption::VALUE_OPTIONAL, 'Define a password hashed, work only with password_nonce') ->addOption('password_nonce', null, InputOption::VALUE_OPTIONAL, 'Define a password nonce, work only with password_hash') - ->addOption('get_hash', null, InputOption::VALUE_NONE, 'return the password hashed') + ->addOption('get_hash', null, InputOption::VALUE_NONE, 'Return the password hashed and nonce') ->setHelp(''); From dcc28d519447f6b9ca7a146b54bedcf101f4afcd Mon Sep 17 00:00:00 2001 From: aynsix Date: Mon, 2 Mar 2020 14:05:30 +0300 Subject: [PATCH 4/7] change template mail and add option --- .../Command/User/UserPasswordCommand.php | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php index c0197ee417..e2073d6f9f 100644 --- a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php +++ b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php @@ -16,7 +16,7 @@ use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Core\LazyLocator; use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Notification\Receiver; -use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup; +use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordUpdate; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -32,7 +32,7 @@ class UserPasswordCommand extends Command { parent::__construct('user:password'); - $this->setDescription('Set user password in Phraseanet') + $this->setDescription('Set user password in Phraseanet (experimental)') ->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.') ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate and set with a random value') ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Set the user password to the input value') @@ -40,6 +40,8 @@ class UserPasswordCommand extends Command ->addOption('password_hash', null, InputOption::VALUE_OPTIONAL, 'Define a password hashed, work only with password_nonce') ->addOption('password_nonce', null, InputOption::VALUE_OPTIONAL, 'Define a password nonce, work only with password_hash') ->addOption('get_hash', null, InputOption::VALUE_NONE, 'Return the password hashed and nonce') + ->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format') + ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions') ->setHelp(''); @@ -59,6 +61,8 @@ class UserPasswordCommand extends Command $getHash = $input->getOption('get_hash'); $passwordHash = $input->getOption('password_hash'); $passwordNonce = $input->getOption('password_nonce'); + $jsonformat = $input->getOption('jsonformat'); + $yes = $input->getOption('yes'); if ($user === null) { @@ -81,7 +85,8 @@ class UserPasswordCommand extends Command } else { if (!$password && $sendMailPassword) { $this->sendPasswordSetupMail($user); - + $output->writeln('email link sended for password renewing!'); + return 0; } elseif (!$password && !$sendMailPassword && ! $getHash) { $output->writeln('choose one option to set a password!'); @@ -91,26 +96,40 @@ class UserPasswordCommand extends Command } if ($password) { - do { - $continue = mb_strtolower($dialog->ask($output, 'Do you want really set password to this user? (y/N)', 'N')); - } while (!in_array($continue, ['y', 'n'])); + if (!$yes) { + do { + $continue = mb_strtolower($dialog->ask($output, 'Do you want really set password to this user? (y/N)', 'N')); + } while (!in_array($continue, ['y', 'n'])); - if ($continue !== 'y') { - $output->writeln('Aborting !'); + if ($continue !== 'y') { + $output->writeln('Aborting !'); - return; + return; + } } $userManipulator->setPassword($user,$password); } if (($password || $generate || $getHash) && $user->getPassword()) { - $hash = [ - 'password' => $user->getPassword(), - 'nonce' => $user->getNonce() - ]; - echo json_encode($hash); + if ($jsonformat) { + if ($password) { + $hash['password'] = $password; + } + + $hash['password_hash'] = $user->getPassword(); + $hash['nonce'] = $user->getNonce(); + + echo json_encode($hash); + } else { + if ($password) { + $output->writeln('password :' .$password); + } + $output->writeln('password_hash :' .$user->getPassword()); + $output->writeln('nonce :' .$user->getNonce()); + } + } elseif (is_null($password)) { $output->writeln('password undefined'); } @@ -129,7 +148,7 @@ class UserPasswordCommand extends Command $token = $this->container['manipulator.token']->createResetPasswordToken($user); - $mail = MailRequestPasswordSetup::create($this->container, $receiver); + $mail = MailRequestPasswordUpdate::create($this->container, $receiver); $servername = $this->container['conf']->get('servername'); $mail->setButtonUrl('http://'.$servername.'/login/renew-password/?token='.$token->getValue()); $mail->setLogin($user->getLogin()); From bb356e206f9d49878aa43a53d9b5650deff47ef6 Mon Sep 17 00:00:00 2001 From: aynsix Date: Tue, 3 Mar 2020 11:41:15 +0300 Subject: [PATCH 5/7] fix mail link and returned hash --- .../Command/User/UserPasswordCommand.php | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php index e2073d6f9f..9e282966b1 100644 --- a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php +++ b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php @@ -36,7 +36,7 @@ class UserPasswordCommand extends Command ->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.') ->addOption('generate', null, InputOption::VALUE_NONE, 'Generate and set with a random value') ->addOption('password', null, InputOption::VALUE_OPTIONAL, 'Set the user password to the input value') - ->addOption('send_mail_password', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if --password or --generate are not define') + ->addOption('send_renewal_email', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if --password or --generate are not define') ->addOption('password_hash', null, InputOption::VALUE_OPTIONAL, 'Define a password hashed, work only with password_nonce') ->addOption('password_nonce', null, InputOption::VALUE_OPTIONAL, 'Define a password nonce, work only with password_hash') ->addOption('get_hash', null, InputOption::VALUE_NONE, 'Return the password hashed and nonce') @@ -57,7 +57,7 @@ class UserPasswordCommand extends Command $user = $userRepository->find($input->getOption('user_id')); $password = $input->getOption('password'); $generate = $input->getOption('generate'); - $sendMailPassword = $input->getOption('send_mail_password'); + $sendRenewalEmail = $input->getOption('send_renewal_email'); $getHash = $input->getOption('get_hash'); $passwordHash = $input->getOption('password_hash'); $passwordNonce = $input->getOption('password_nonce'); @@ -80,15 +80,23 @@ class UserPasswordCommand extends Command return 0; } + if ($getHash) { + $oldHash = $user->getPassword(); + $oldNonce = $user->getNonce(); + } + if ($generate) { + $oldHash = $user->getPassword(); + $oldNonce = $user->getNonce(); + $password = $this->container['random.medium']->generateString(64); } else { - if (!$password && $sendMailPassword) { + if (!$password && $sendRenewalEmail) { $this->sendPasswordSetupMail($user); $output->writeln('email link sended for password renewing!'); return 0; - } elseif (!$password && !$sendMailPassword && ! $getHash) { + } elseif (!$password && !$sendRenewalEmail && ! $getHash) { $output->writeln('choose one option to set a password!'); return 0; @@ -107,27 +115,21 @@ class UserPasswordCommand extends Command return; } } + $oldHash = $user->getPassword(); + $oldNonce = $user->getNonce(); - $userManipulator->setPassword($user,$password); + $userManipulator->setPassword($user,$password); } - if (($password || $generate || $getHash) && $user->getPassword()) { - + if (($password || $generate || $getHash) && $oldHash) { if ($jsonformat) { - if ($password) { - $hash['password'] = $password; - } - - $hash['password_hash'] = $user->getPassword(); - $hash['nonce'] = $user->getNonce(); + $hash['password_hash'] = $oldHash; + $hash['nonce'] = $oldNonce; echo json_encode($hash); } else { - if ($password) { - $output->writeln('password :' .$password); - } - $output->writeln('password_hash :' .$user->getPassword()); - $output->writeln('nonce :' .$user->getNonce()); + $output->writeln('password_hash :' . $oldHash); + $output->writeln('nonce :' . $oldNonce); } } elseif (is_null($password)) { @@ -147,11 +149,13 @@ class UserPasswordCommand extends Command $receiver = Receiver::fromUser($user); $token = $this->container['manipulator.token']->createResetPasswordToken($user); - + + $url = $this->container['url_generator']->generate('login_renew_password', [ 'token' => $token->getValue() ], true); $mail = MailRequestPasswordUpdate::create($this->container, $receiver); $servername = $this->container['conf']->get('servername'); - $mail->setButtonUrl('http://'.$servername.'/login/renew-password/?token='.$token->getValue()); + $mail->setButtonUrl($url); $mail->setLogin($user->getLogin()); + $mail->setExpiration(new \DateTime('+1 day')); $this->deliver($mail); } From 354b1b8e6efa92aac7557b8a536ac20362b91c04 Mon Sep 17 00:00:00 2001 From: aynsix Date: Tue, 3 Mar 2020 12:12:44 +0300 Subject: [PATCH 6/7] fix return --- .../Phrasea/Command/User/UserPasswordCommand.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php index 9e282966b1..bd87c4d885 100644 --- a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php +++ b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php @@ -123,11 +123,17 @@ class UserPasswordCommand extends Command if (($password || $generate || $getHash) && $oldHash) { if ($jsonformat) { - $hash['password_hash'] = $oldHash; - $hash['nonce'] = $oldNonce; + if ($password) { + $hash['new_password'] = $password; + } + $hash['password_hash'] = $oldHash; + $hash['nonce'] = $oldNonce; echo json_encode($hash); } else { + if ($password) { + $output->writeln('new_password :' . $password); + } $output->writeln('password_hash :' . $oldHash); $output->writeln('nonce :' . $oldNonce); } From 87d6ea0eb396ca0dbaca2e32d897ccd36059f84c Mon Sep 17 00:00:00 2001 From: aynsix Date: Wed, 4 Mar 2020 10:58:43 +0300 Subject: [PATCH 7/7] fix wording --- .../Command/User/UserPasswordCommand.php | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php index bd87c4d885..94e400aa14 100644 --- a/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php +++ b/lib/Alchemy/Phrasea/Command/User/UserPasswordCommand.php @@ -39,7 +39,7 @@ class UserPasswordCommand extends Command ->addOption('send_renewal_email', null, InputOption::VALUE_NONE, 'Send email link to user for password renewing, work only if --password or --generate are not define') ->addOption('password_hash', null, InputOption::VALUE_OPTIONAL, 'Define a password hashed, work only with password_nonce') ->addOption('password_nonce', null, InputOption::VALUE_OPTIONAL, 'Define a password nonce, work only with password_hash') - ->addOption('get_hash', null, InputOption::VALUE_NONE, 'Return the password hashed and nonce') + ->addOption('dump', null, InputOption::VALUE_NONE, 'Return the password hashed and nonce') ->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format') ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions') @@ -58,7 +58,7 @@ class UserPasswordCommand extends Command $password = $input->getOption('password'); $generate = $input->getOption('generate'); $sendRenewalEmail = $input->getOption('send_renewal_email'); - $getHash = $input->getOption('get_hash'); + $dump = $input->getOption('dump'); $passwordHash = $input->getOption('password_hash'); $passwordNonce = $input->getOption('password_nonce'); $jsonformat = $input->getOption('jsonformat'); @@ -80,7 +80,7 @@ class UserPasswordCommand extends Command return 0; } - if ($getHash) { + if ($dump) { $oldHash = $user->getPassword(); $oldNonce = $user->getNonce(); } @@ -96,7 +96,7 @@ class UserPasswordCommand extends Command $output->writeln('email link sended for password renewing!'); return 0; - } elseif (!$password && !$sendRenewalEmail && ! $getHash) { + } elseif (!$password && !$sendRenewalEmail && ! $dump) { $output->writeln('choose one option to set a password!'); return 0; @@ -121,25 +121,34 @@ class UserPasswordCommand extends Command $userManipulator->setPassword($user,$password); } - if (($password || $generate || $getHash) && $oldHash) { + if ($dump) { if ($jsonformat) { - if ($password) { - $hash['new_password'] = $password; - } $hash['password_hash'] = $oldHash; $hash['nonce'] = $oldNonce; echo json_encode($hash); + + return 0; } else { - if ($password) { - $output->writeln('new_password :' . $password); - } $output->writeln('password_hash :' . $oldHash); $output->writeln('nonce :' . $oldNonce); + + return 0; + } + } + + if (($password || $generate)) { + if ($jsonformat) { + $hash['new_password'] = $password; + $hash['previous_password_hash'] = $oldHash; + $hash['previous_nonce'] = $oldNonce; + + echo json_encode($hash); + } else { + $output->writeln('new_password :' . $password); + $output->writeln('previous_password_hash :' . $oldHash); + $output->writeln('previous_nonce :' . $oldNonce); } - - } elseif (is_null($password)) { - $output->writeln('password undefined'); } return 0;