2017-07-21 01:09:02 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
namespace App\Console\Command\Users;
|
2017-07-21 01:09:02 +00:00
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
use App\Console\Command\CommandAbstract;
|
2018-08-04 22:05:14 +00:00
|
|
|
use App\Entity;
|
2019-09-04 18:00:51 +00:00
|
|
|
use App\Utilities;
|
2020-06-26 20:22:53 +00:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
2018-05-31 17:01:03 +00:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2017-07-21 01:09:02 +00:00
|
|
|
|
2019-09-10 23:10:57 +00:00
|
|
|
class ResetPasswordCommand extends CommandAbstract
|
2017-07-21 01:09:02 +00:00
|
|
|
{
|
2019-09-10 23:10:57 +00:00
|
|
|
public function __invoke(
|
|
|
|
SymfonyStyle $io,
|
2020-06-26 20:22:53 +00:00
|
|
|
EntityManagerInterface $em,
|
2019-09-10 23:10:57 +00:00
|
|
|
string $email
|
2020-10-14 22:19:31 +00:00
|
|
|
): int {
|
2018-05-31 17:01:03 +00:00
|
|
|
$io->title('Reset Account Password');
|
|
|
|
|
2017-07-21 01:09:02 +00:00
|
|
|
$user = $em->getRepository(Entity\User::class)
|
2019-09-10 23:10:57 +00:00
|
|
|
->findOneBy(['email' => $email]);
|
2017-07-21 01:09:02 +00:00
|
|
|
|
|
|
|
if ($user instanceof Entity\User) {
|
2020-12-11 02:43:58 +00:00
|
|
|
$temp_pw = Utilities\Strings::generatePassword(15);
|
2017-07-21 01:09:02 +00:00
|
|
|
|
2019-10-26 23:35:24 +00:00
|
|
|
$user->setNewPassword($temp_pw);
|
2021-04-23 22:12:47 +00:00
|
|
|
$user->setTwoFactorSecret();
|
2017-07-21 01:09:02 +00:00
|
|
|
|
|
|
|
$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
|
|
|
'',
|
2019-09-04 18:00:51 +00:00
|
|
|
' ' . $temp_pw,
|
2018-05-31 17:01:03 +00:00
|
|
|
'',
|
|
|
|
'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
|
|
|
}
|
2019-02-18 00:52:01 +00:00
|
|
|
|
|
|
|
$io->error('Account not found.');
|
|
|
|
return 1;
|
2017-07-21 01:09:02 +00:00
|
|
|
}
|
2018-08-04 22:05:14 +00:00
|
|
|
}
|