2017-07-21 01:09:02 +00:00
|
|
|
<?php
|
2018-08-04 22:05:14 +00:00
|
|
|
namespace App\Console\Command;
|
2017-07-21 01:09:02 +00:00
|
|
|
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Entity;
|
2018-11-12 16:59:15 +00:00
|
|
|
use Azura\Console\Command\CommandAbstract;
|
2017-07-21 01:09:02 +00:00
|
|
|
use Doctrine\ORM\EntityManager;
|
2017-07-31 22:33:30 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2017-07-21 01:09:02 +00:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2018-05-31 17:01:03 +00:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-07-21 01:09:02 +00:00
|
|
|
|
2018-11-12 16:59:15 +00:00
|
|
|
class ResetPassword extends CommandAbstract
|
2017-07-21 01:09:02 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this->setName('azuracast:account:reset-password')
|
|
|
|
->setDescription('Reset the password of the specified account.')
|
|
|
|
->addArgument(
|
|
|
|
'email',
|
2017-07-31 22:33:30 +00:00
|
|
|
InputArgument::REQUIRED,
|
|
|
|
'The user\'s e-mail address.'
|
2017-07-21 01:09:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2018-05-31 17:01:03 +00:00
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
|
|
$io->title('Reset Account Password');
|
|
|
|
|
2017-07-21 01:09:02 +00:00
|
|
|
/** @var EntityManager $em */
|
2018-05-07 01:57:06 +00:00
|
|
|
$em = $this->get(EntityManager::class);
|
2017-07-21 01:09:02 +00:00
|
|
|
|
|
|
|
$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();
|
|
|
|
|
2018-05-31 17:01:03 +00:00
|
|
|
$io->text([
|
2017-07-21 01:09:02 +00:00
|
|
|
'The account password has been reset. The new temporary password is:',
|
2018-05-31 17:01:03 +00:00
|
|
|
'',
|
|
|
|
' '.$temp_pw,
|
|
|
|
'',
|
|
|
|
'Log in using this temporary password and set a new password using the web interface.',
|
|
|
|
'',
|
2017-07-21 01:09:02 +00:00
|
|
|
]);
|
2018-05-07 01:57:06 +00:00
|
|
|
return 0;
|
2017-07-21 01:09:02 +00:00
|
|
|
} else {
|
2018-05-31 17:01:03 +00:00
|
|
|
$io->error('Account not found.');
|
2018-05-07 01:57:06 +00:00
|
|
|
return 1;
|
2017-07-21 01:09:02 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|