1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Dontdrinkandroot\Gitki\WebBundle\Command; |
5
|
|
|
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
9
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
10
|
|
|
|
11
|
|
|
class UserEditCommand extends AbstractUserCommand |
12
|
|
|
{ |
13
|
|
|
const FIELD_PASSWORD = 'Password'; |
14
|
|
|
const FIELD_REAL_NAME = 'Real Name'; |
15
|
|
|
|
16
|
|
|
protected function configure() |
17
|
|
|
{ |
18
|
|
|
$this |
19
|
|
|
->setName('gitki:user:edit') |
20
|
|
|
->setDescription('Edits an existing user'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
24
|
|
|
{ |
25
|
|
|
$userManager = $this->getUserManager(); |
26
|
|
|
$questionHelper = $this->getQuestionHelper(); |
27
|
|
|
|
28
|
|
|
$user = $this->selectUser($input, $output); |
29
|
|
|
|
30
|
|
|
$fields = [ |
31
|
|
|
self::FIELD_REAL_NAME, |
32
|
|
|
'Email', |
33
|
|
|
'Role', |
34
|
|
|
self::FIELD_PASSWORD, |
35
|
|
|
'Github Login', |
36
|
|
|
'Google Login', |
37
|
|
|
'Done' |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
$fieldQuestion = new ChoiceQuestion( |
41
|
|
|
'Select Field: ', |
42
|
|
|
$fields |
43
|
|
|
); |
44
|
|
|
do { |
45
|
|
|
$this->printUser($user, $output); |
46
|
|
|
$field = $questionHelper->ask($input, $output, $fieldQuestion); |
47
|
|
|
switch ($field) { |
48
|
|
|
case self::FIELD_REAL_NAME: |
49
|
|
|
$user = $this->editRealName($input, $output, $user, $questionHelper); |
50
|
|
|
break; |
51
|
|
|
case 'Email': |
52
|
|
|
$user = $this->editEmail($input, $output, $user, $questionHelper); |
53
|
|
|
break; |
54
|
|
|
case 'Role': |
55
|
|
|
$user = $this->editRole($input, $output, $user, $questionHelper); |
56
|
|
|
break; |
57
|
|
|
case self::FIELD_PASSWORD: |
58
|
|
|
$user = $this->editPassword($input, $output, $user, $questionHelper, $userManager); |
59
|
|
|
break; |
60
|
|
|
case 'Github Login': |
61
|
|
|
$user = $this->editGithubId($input, $output, $user, $questionHelper); |
62
|
|
|
break; |
63
|
|
|
case 'Google Login': |
64
|
|
|
$user = $this->editGoogleId($input, $output, $user, $questionHelper); |
65
|
|
|
break; |
66
|
|
|
} |
67
|
|
|
} while ('Done' !== $field); |
68
|
|
|
|
69
|
|
|
$this->printUser($user, $output); |
70
|
|
|
|
71
|
|
|
$saveQuestion = new ConfirmationQuestion('Save? ', false); |
72
|
|
|
if ($questionHelper->ask($input, $output, $saveQuestion)) { |
73
|
|
|
$userManager->updateUser($user); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|