|
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
|
|
|
|
|
27
|
|
|
$this->io->section('User informations'); |
|
28
|
|
|
$username = $this->askUsername(); |
|
29
|
|
|
$email = $this->askEmail(); |
|
30
|
|
|
$password = $this->askPassword(); |
|
31
|
|
|
$active = $this->io->confirm('Activate the user (or send him an activation email)', false); |
|
32
|
|
|
|
|
33
|
|
|
$coach = (new Coach()) |
|
34
|
|
|
->setUsername($username) |
|
35
|
|
|
->setEmail($email) |
|
36
|
|
|
->setPassword($password) |
|
37
|
|
|
->setActive($active) |
|
38
|
|
|
->setLocale('en') |
|
39
|
|
|
->setRoles([Roles::ADMIN]) |
|
40
|
|
|
; |
|
41
|
|
|
if(!$active) { |
|
42
|
|
|
$coach |
|
43
|
|
|
->setHash(hash('sha256', $coach->getEmail())); |
|
44
|
|
|
$registration = new RegisterCoachEvent($coach); |
|
45
|
|
|
$this->dispatch($registration, RegisterCoachEvent::NAME); |
|
46
|
|
|
} |
|
47
|
|
|
$this->saveCoach($coach); |
|
48
|
|
|
$this->io->success("The coach $username has been created !"); |
|
49
|
|
|
return 1; |
|
50
|
|
|
} |
|
51
|
|
|
$this->io->text('Aborted.'); |
|
52
|
|
|
return 0; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|