#192 -- Add account recovery script to CLI library.

This commit is contained in:
Buster Silver 2017-07-20 20:09:02 -05:00
parent cc5380c3cf
commit 0e12a531c7
4 changed files with 63 additions and 2 deletions

View File

@ -57,7 +57,7 @@ return [
'description' => _('All times displayed on the site will be based on this time zone.') . '<br>' . sprintf(_('Current server time is <b>%s</b>.'),
date('g:ia')),
'options' => \App\Timezone::fetchSelect(),
'default' => date_default_timezone_get(),
'default' => 'UTC',
]
],

View File

@ -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.');
}

View File

@ -0,0 +1,60 @@
<?php
namespace AzuraCast\Console\Command;
use Entity;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ResetPassword extends \App\Console\Command\CommandAbstract
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->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;
}
}
}

View File

@ -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();