Skip to content

Commit

Permalink
Fixed login command + use table() from prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
SRWieZ committed Jul 17, 2024
1 parent 348a4da commit 0f25061
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 18 deletions.
11 changes: 6 additions & 5 deletions app/Commands/DigCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use React\Dns\Query\UdpTransportExecutor;

use function Laravel\Prompts\select;
use function Laravel\Prompts\table;

class DigCommand extends Command implements PromptsForMissingInput
{
Expand Down Expand Up @@ -49,14 +50,14 @@ public function handle()
->then(function (Message $message) use (&$table, $type_string) {
foreach ($message->answers as $answer) {
$table[] = [
'Name' => $answer->name,
'Type' => $type_string,
'TTL' => $answer->ttl,
'Value' => is_array($answer->data) ? implode(' ', $answer->data) : $answer->data,
$answer->name,
$type_string,
$answer->ttl,
is_array($answer->data) ? implode(' ', $answer->data) : $answer->data,
];
}

$this->table(['Name', 'Type', 'TTL', 'Value'], $table);
table(['Name', 'Type', 'TTL', 'Value'], $table);
}, fn (\Throwable $e) => $this->error($e->getMessage()));

}
Expand Down
4 changes: 3 additions & 1 deletion app/Commands/DomainListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Unolia\UnoliaCLI\Helpers\Helpers;
use Unolia\UnoliaCLI\Http\Integrations\Unolia\Requests\Domains;

use function Laravel\Prompts\table;

class DomainListCommand extends Command
{
protected $signature = 'domain:list';
Expand All @@ -25,6 +27,6 @@ public function handle()
'Last synced at' => $domain['synced_at'] ? Carbon::make($domain['synced_at'])->diffForHumans() : 'Never synced',
])->toArray();

$this->table(['Domain', 'Team', 'Last Synced At'], $table);
table(['Domain', 'Team', 'Last Synced At'], $table);
}
}
6 changes: 4 additions & 2 deletions app/Commands/DomainRecordsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Unolia\UnoliaCLI\Helpers\Helpers;
use Unolia\UnoliaCLI\Http\Integrations\Unolia\Requests\DomainsRecords;

use function Laravel\Prompts\table;

class DomainRecordsCommand extends Command implements PromptsForMissingInput
{
protected $signature = 'domain:records {domain}';
Expand All @@ -24,12 +26,12 @@ public function handle()
'#' => $record['id'],
'name' => $record['name'],
'type' => $record['type'],
'ttl' => $record['ttl'],
'ttl' => $record['ttl'] ?: '---',
'value' => Str::limit($record['value'], 20),
'state' => $record['state'],
])->toArray();

$this->table(['#', 'Name', 'Type', 'TTL', 'Value', 'State'], $table);
table(['#', 'Name', 'Type', 'TTL', 'Value', 'State'], $table);
}

protected function promptForMissingArgumentsUsing(): array
Expand Down
28 changes: 19 additions & 9 deletions app/Commands/LoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Unolia\UnoliaCLI\Http\Integrations\Unolia\Requests\CurrentToken;
use Unolia\UnoliaCLI\Http\Integrations\Unolia\Requests\Login;

use function Laravel\Prompts\password;
use function Laravel\Prompts\form;
use function Laravel\Prompts\text;

class LoginCommand extends Command
Expand All @@ -31,22 +31,31 @@ public function handle()
$verify->throw();

$this->line('You are already logged in.');
} catch (Exception) {
}

return;
return;
} catch (Exception $e) {
\Laravel\Prompts\info('A token is already set, but it is expired. Please login again.');
}
}

$token_name = 'Token for '.get_current_user().'@'.gethostname();

$email = text('Email');
$password = password('Password');
$host = parse_url(config('settings.api.auth_url'), PHP_URL_HOST);
$responses = form()
->text('Email',
required: true,
hint: 'Please provide your login credentials to '.$host,
name: 'email'
)
->password('Password', required: true, name: 'password')
->submit();

$connector_auth = Helpers::getAuthConnector();

try {
$login = $connector_auth->send(new Login(
email: $email,
password: $password,
email: $responses['email'],
password: $responses['password'],
token_name: $token_name,
));

Expand All @@ -60,7 +69,8 @@ public function handle()
$two_factor_code = text('Two factor authentication code');

$login = $connector_auth->send(new Login(
email: $email, password: $password,
email: $responses['email'],
password: $responses['password'],
two_factor_code: $two_factor_code,
token_name: $token_name,
));
Expand Down
4 changes: 3 additions & 1 deletion app/Commands/TeamsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Unolia\UnoliaCLI\Helpers\Helpers;
use Unolia\UnoliaCLI\Http\Integrations\Unolia\Requests\Teams;

use function Laravel\Prompts\table;

class TeamsCommand extends Command
{
protected $signature = 'teams';
Expand All @@ -23,6 +25,6 @@ public function handle()
'Team' => $team['name'],
])->toArray();

$this->table(['ID', 'Team'], $table);
table(['ID', 'Team'], $table);
}
}
Binary file modified builds/unolia
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/Feature/LoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
it('can authenticate a user', function () {});

it('can authenticate a user with a token as parameter', function () {});

it('can authenticate a user with 2fa', function () {});

it('can authenticate a user whit an expired token in the config', function () {});

0 comments on commit 0f25061

Please sign in to comment.