1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
6
|
|
|
use Obblm\Core\Entity\Coach; |
7
|
|
|
use Obblm\Core\Event\RegisterCoachEvent; |
8
|
|
|
use Obblm\Core\Security\Roles; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class CreateAdminCommand extends AbstractAdminCommand |
13
|
|
|
{ |
14
|
|
|
/** @var string */ |
15
|
|
|
protected static $defaultName = 'obblm:coach:create-admin'; |
16
|
|
|
protected static $description = 'Creates a new OBBLM Administrator.'; |
17
|
|
|
protected static $help = 'This command will add a new administrator.'; |
18
|
|
|
|
19
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
20
|
|
|
{ |
21
|
|
|
parent::execute($input, $output); |
22
|
|
|
$this->io->title('Create a new OBBLM Administrator'); |
23
|
|
|
$this->io->caution('Be carefull, this new user will have the highest right on the application'); |
24
|
|
|
|
25
|
|
|
if ($this->confirmContinue()) { |
26
|
|
|
$this->io->section('User informations'); |
27
|
|
|
$username = $this->askUsername(); |
28
|
|
|
$email = $this->askEmail(); |
29
|
|
|
$password = $this->askPassword(); |
30
|
|
|
$active = $this->io->confirm('Activate the user (or send him an activation email)', false); |
31
|
|
|
|
32
|
|
|
$coach = (new Coach()) |
33
|
|
|
->setUsername($username) |
34
|
|
|
->setEmail($email) |
35
|
|
|
->setPassword($password) |
36
|
|
|
->setActive($active) |
37
|
|
|
->setLocale('en') |
38
|
|
|
->setRoles([Roles::ADMIN]) |
39
|
|
|
; |
40
|
|
|
if (!$active) { |
41
|
|
|
$coach |
42
|
|
|
->setHash(hash('sha256', $coach->getEmail())); |
43
|
|
|
$registration = new RegisterCoachEvent($coach); |
44
|
|
|
$this->dispatch($registration, RegisterCoachEvent::NAME); |
45
|
|
|
} |
46
|
|
|
$this->saveCoach($coach); |
47
|
|
|
$this->io->success("The coach $username has been created !"); |
48
|
|
|
return 1; |
49
|
|
|
} |
50
|
|
|
$this->io->text('Aborted.'); |
51
|
|
|
return 0; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|