Beispiel #1
0
 protected function execute_create(InputInterface $input, OutputInterface $output)
 {
     $client = $input->getOption('client');
     if (!$client) {
         // We can't use the generic `get_client()` for **creation**,
         // because we need to verify that the user does **not** exist.
         $clients = Arr::pluck(Ushahidi_Console_OAuth_Client::db_list(), 'client_id');
         $ask = function ($client) use($clients) {
             if (in_array($client, $clients)) {
                 throw new RuntimeException('Client "' . $client . '" already exists, try another name');
             }
             return $client;
         };
         $client = $this->getHelperSet()->get('dialog')->askAndValidate($output, 'Enter name of new client: ', $ask, FALSE);
     }
     $secret = $input->getOption('secret');
     $redirect = $input->getOption('redirect');
     if (!$secret) {
         $secret = Text::random('distinct', 24);
     }
     if (!$redirect) {
         $redirect = '/';
     }
     static::db_create(['client_id' => $client, 'client_secret' => $secret, 'redirect_uri' => $redirect]);
     $input->setOption('client', $client);
     return $this->execute_list($input, $output);
 }
Beispiel #2
0
 protected function get_client(InputInterface $input, OutputInterface $output = NULL)
 {
     $client = $input->getOption('client');
     if (!$client and $output) {
         // If no client was given, and `$output` is passed, we can ask for
         // the user interactively and validate it against the known clients.
         $clients = Arr::pluck(Ushahidi_Console_OAuth_Client::db_list(), 'client_id');
         $ask = function ($client) use($clients) {
             if (!in_array($client, $clients)) {
                 throw new RuntimeException('Unknown client "' . $client . '", valid options are: ' . implode(', ', $clients));
             }
             return $client;
         };
         $client = $this->getHelperSet()->get('dialog')->askAndValidate($output, 'For which client? ', $ask, FALSE, NULL, $clients);
     }
     return $client;
 }