-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathPasswordCommand.php
More file actions
83 lines (68 loc) · 2.79 KB
/
PasswordCommand.php
File metadata and controls
83 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@h-hennes.fr so we can send you a copy immediately.
*
* @author Hennes Hervé <contact@h-hennes.fr>
* @copyright since 2016 Hennes Hervé
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* https://github.com/nenes25/prestashop_console
* https://www.h-hennes.fr/blog/
*/
namespace PrestashopConsole\Command\Admin\User;
use Employee;
use PrestashopConsole\Command\PrestashopConsoleAbstractCmd as Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
/**
* Change admin password
*/
class PasswordCommand extends Command
{
protected function configure(): void
{
$this
->setName('admin:user:change-password')
->setDescription('Change admin user password');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$helper = $this->getHelper('question');
$userQuestion = new Question('user email :', false);
$email = $helper->ask($input, $output, $userQuestion);
// Error if no employee exists with email
if (!Employee::employeeExists($email)) {
$output->writeln('<error>Employee with this email not exists');
return self::RESPONSE_ERROR;
}
$passwordQuestion = new Question('admin password :', 'admin123456');
$passwordQuestion->setHidden(true);
$password = $helper->ask($input, $output, $passwordQuestion);
$passwordConfirmQuestion = new Question('confirm admin password :', 'admin123456');
$passwordConfirmQuestion->setHidden(true);
$passwordConfirm = $helper->ask($input, $output, $passwordConfirmQuestion);
if ($password !== $passwordConfirm) {
$output->writeln('<error>Password and password confirmation do not match');
return self::RESPONSE_ERROR;
}
$employee = new Employee();
$employee->getByEmail($email);
$employee->passwd = \Tools::encrypt($password);
try {
$employee->save();
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return self::RESPONSE_ERROR;
}
$output->writeln('<info>Password changed with success for user ' . $email . '</info>');
return self::RESPONSE_SUCCESS;
}
}