From 0e12a531c7de7790363c3526de50fe794fcd348c Mon Sep 17 00:00:00 2001 From: Buster Silver Date: Thu, 20 Jul 2017 20:09:02 -0500 Subject: [PATCH] #192 -- Add account recovery script to CLI library. --- app/config/forms/profile.conf.php | 2 +- .../Console/Command/ReprocessMedia.php | 2 +- .../Console/Command/ResetPassword.php | 60 +++++++++++++++++++ util/cli.php | 1 + 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 app/src/AzuraCast/Console/Command/ResetPassword.php diff --git a/app/config/forms/profile.conf.php b/app/config/forms/profile.conf.php index e5b2231f5..006ce8276 100644 --- a/app/config/forms/profile.conf.php +++ b/app/config/forms/profile.conf.php @@ -57,7 +57,7 @@ return [ 'description' => _('All times displayed on the site will be based on this time zone.') . '
' . sprintf(_('Current server time is %s.'), date('g:ia')), 'options' => \App\Timezone::fetchSelect(), - 'default' => date_default_timezone_get(), + 'default' => 'UTC', ] ], diff --git a/app/src/AzuraCast/Console/Command/ReprocessMedia.php b/app/src/AzuraCast/Console/Command/ReprocessMedia.php index 728d54674..b1cfbbcc4 100644 --- a/app/src/AzuraCast/Console/Command/ReprocessMedia.php +++ b/app/src/AzuraCast/Console/Command/ReprocessMedia.php @@ -13,7 +13,7 @@ class ReprocessMedia extends \App\Console\Command\CommandAbstract */ protected function configure() { - $this->setName('media:reprocess') + $this->setName('azuracast:media:reprocess') ->setDescription('Manually reload all media metadata from file.'); } diff --git a/app/src/AzuraCast/Console/Command/ResetPassword.php b/app/src/AzuraCast/Console/Command/ResetPassword.php new file mode 100644 index 000000000..ee81824d2 --- /dev/null +++ b/app/src/AzuraCast/Console/Command/ResetPassword.php @@ -0,0 +1,60 @@ +setName('azuracast:account:reset-password') + ->setDescription('Reset the password of the specified account.') + ->addArgument( + 'email', + null, + 'The user\'s e-mail address.', + null + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + /** @var EntityManager $em */ + $em = $this->di['em']; + + $user_email = $input->getArgument('email'); + + $user = $em->getRepository(Entity\User::class) + ->findOneBy(['email' => $user_email ]); + + if ($user instanceof Entity\User) { + $temp_pw = \App\Utilities::generatePassword(15); + + $user->setAuthPassword($temp_pw); + + $em->persist($user); + $em->flush(); + + $output->writeLn([ + 'The account password has been reset. The new temporary password is:', + ' ', + $temp_pw, + ' ', + 'Set a new password using the web interface.', + ]); + return true; + } else { + $output->writeln('Account not found.'); + return false; + } + } +} \ No newline at end of file diff --git a/util/cli.php b/util/cli.php index c2c98e849..e45452e81 100644 --- a/util/cli.php +++ b/util/cli.php @@ -56,6 +56,7 @@ $cli->addCommands([ new \AzuraCast\Console\Command\GenerateApiDocs($di), new \AzuraCast\Console\Command\UptimeWait($di), new \AzuraCast\Console\Command\MigrateConfig($di), + new \AzuraCast\Console\Command\ResetPassword($di), ]); $cli->run(); \ No newline at end of file