protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output);
if (!$this->initMagento()) {
return;
}
/* @var $dialog DialogHelper */
$dialog = $this->getHelper('dialog');
// Username
if (($username = $input->getArgument('username')) == null) {
$username = $dialog->ask($output, '<question>Username:</question>');
}
$user = $this->getUserModel()->loadByUsername($username);
if ($user->getId() <= 0) {
$output->writeln('<error>User was not found</error>');
return;
}
// Password
if (($password = $input->getArgument('password')) == null) {
$password = $dialog->askHiddenResponse($output, '<question>Password:</question>');
}
try {
$result = $user->validate();
if (is_array($result)) {
throw new RuntimeException(implode(PHP_EOL, $result));
}
$user->setPassword($password);
$user->save();
$output->writeln('<info>Password successfully changed</info>');
} catch (Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
}
}