setName('auth:login') ->setDescription('Login on t411') ->setHelp("%command.name% Generate the config to access the API. You must have a valid login/password. The login and the password are not saved. Usage: auth:login"); } protected function execute(InputInterface $input, OutputInterface $output) { $configLoader = new ConfigLoader(); $dialog = $this->getHelperSet()->get('dialog'); $client = new Client(); if ($configLoader->configExists()) { $continue = $dialog->askConfirmation( $output, 'The configuration file already exists. Do you want to continue? [yes] ', true ); if (!$continue) { $output->writeln('Aborded.'); return; } } $username = $dialog->ask($output, 'Username: ', null); $password = $dialog->askHiddenResponse($output, 'Password (hidden): ', null); try { $response = $client->getAuthorization($username, $password); if ($response->hasError()) { $output->writeln(sprintf( 'Login failed: %s (%d)', $response->getErrorMessage(), $response->getErrorCode() )); return; } $configLoader->save(array( 'auth' => array( 'uid' => $response->getData()['uid'], 'token' => $response->getData()['token'], ) )); } catch (ClientException $e) { $output->writeln(sprintf('An error occured. %s', $e->getMessage())); } } }