From dcc28d519447f6b9ca7a146b54bedcf101f4afcd Mon Sep 17 00:00:00 2001 From: aynsix Date: Mon, 2 Mar 2020 14:05:30 +0300 Subject: [PATCH] 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());