1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\Users\Console; |
4
|
|
|
|
5
|
|
|
use Backend\Modules\Users\Engine\Model as BackendUsersModel; |
6
|
|
|
use Backend\Core\Engine\User as BackendUser; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Question\Question; |
12
|
|
|
|
13
|
|
|
class ResetPasswordCommand extends Command |
14
|
|
|
{ |
15
|
|
|
protected function configure(): void |
16
|
|
|
{ |
17
|
|
|
$this |
18
|
|
|
->setName('forkcms:users:reset-password') |
19
|
|
|
->setDescription('Reset a users password') |
20
|
|
|
->addArgument('email', InputArgument::OPTIONAL, '(Optional) The users email-address') |
21
|
|
|
->addArgument('password', InputArgument::OPTIONAL, '(Optional) The desired new password'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): void |
25
|
|
|
{ |
26
|
|
|
$helper = $this->getHelper('question'); |
27
|
|
|
|
28
|
|
|
$questionEmailAddress = new Question('Please provide the users email-address: '); |
29
|
|
|
$questionEmailAddressAnswer = $input->getArgument('email'); |
30
|
|
|
|
31
|
|
|
if ($questionEmailAddressAnswer === null) { |
32
|
|
|
$questionEmailAddressAnswer = $helper->ask($input, $output, $questionEmailAddress); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$subjectUserId = BackendUsersModel::getIdByEmail( |
36
|
|
|
$questionEmailAddressAnswer |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
if ($subjectUserId === false) { |
40
|
|
|
$output->writeln( |
41
|
|
|
sprintf('<error>User not found with email-address "%s".</error>', $questionEmailAddressAnswer) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$questionPassword = new Question('Please provide the users new desired password: '); |
48
|
|
|
$questionPassword->setHidden(true); |
49
|
|
|
$questionPasswordAnswer = $input->getArgument('password'); |
50
|
|
|
|
51
|
|
|
if ($questionPasswordAnswer === null) { |
52
|
|
|
$questionPasswordAnswer = $helper->ask($input, $output, $questionPassword); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
BackendUsersModel::updatePassword( |
56
|
|
|
new BackendUser($subjectUserId, $questionEmailAddressAnswer), |
57
|
|
|
$questionPasswordAnswer |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$output->writeln('Password has been updated'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|