|
1
|
|
|
<?php |
|
2
|
|
|
namespace BarenoteCli\Command; |
|
3
|
|
|
|
|
4
|
|
|
use BarenoteCli\BarenoteApplication; |
|
5
|
|
|
use BarenoteCli\Command\Menu\AuthenticatedMenu; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
8
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Question\Question; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class LoginCommand |
|
15
|
|
|
* @package BarenoteCli\Command |
|
16
|
|
|
* @method BarenoteApplication getApplication() |
|
17
|
|
|
*/ |
|
18
|
|
|
class Login extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
const KEY = 'barenote:login'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
$this |
|
28
|
|
|
->setName(self::KEY) |
|
29
|
|
|
->setDescription('Fetches token from the API.') |
|
30
|
|
|
->setHelp('This command allows you to authenticate against API...') |
|
31
|
|
|
->setHidden(true); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
35
|
|
|
{ |
|
36
|
|
|
$client = $this->getApplication()->getClient(); |
|
37
|
|
|
/** @var QuestionHelper $helper */ |
|
38
|
|
|
$helper = $this->getHelper('question'); |
|
39
|
|
|
|
|
40
|
|
|
$question = new Question('Please enter your username' . PHP_EOL, 'dummy'); |
|
41
|
|
|
$question->setAutocompleterValues(['dummy']); |
|
42
|
|
|
$username = $helper->ask($input, $output, $question); |
|
43
|
|
|
|
|
44
|
|
|
$question = new Question('Please enter your password, I promise I won\'t do enything malicious' . PHP_EOL, 'account'); |
|
45
|
|
|
$question->setAutocompleterValues(['account']); |
|
46
|
|
|
$password = $helper->ask($input, $output, $question); |
|
47
|
|
|
|
|
48
|
|
|
$client->authenticate($username, $password); |
|
49
|
|
|
|
|
50
|
|
|
$this->getApplication()->find(AuthenticatedMenu::KEY)->run(new ArrayInput([]), $output); |
|
51
|
|
|
} |
|
52
|
|
|
} |