You've already forked php-auth
generated from siteworxpro/Php-Template
more updates
Some checks failed
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m25s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m35s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Failing after 2m45s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m36s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 2m25s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m10s
Some checks failed
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m25s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m35s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Failing after 2m45s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m36s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 2m25s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 1m10s
This commit is contained in:
@@ -8,60 +8,70 @@ use Siteworxpro\App\Cli\Commands\Command;
|
||||
use Siteworxpro\App\Models\ClientUser;
|
||||
use Siteworxpro\App\Models\User;
|
||||
use Siteworxpro\App\OAuth\Entities\Client;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command as SCommand;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Question\Question as QuestionInput;
|
||||
|
||||
#[AsCommand('user:add', 'Add a new user associated with an OAuth client')]
|
||||
class Add extends Command
|
||||
{
|
||||
public function __construct()
|
||||
public function __invoke($input, $output): int
|
||||
{
|
||||
parent::__construct('user:add', 'Add a new user to the system');
|
||||
}
|
||||
$clients = Client::whereJsonContains('grant_types', 'authorization_code')
|
||||
->get(['id', 'name']);
|
||||
|
||||
public function execute(): int
|
||||
{
|
||||
$clients = Client::all(['id', 'name']);
|
||||
|
||||
$this->climate->info('Available OAuth Clients:');
|
||||
$output->info('Available OAuth Clients:');
|
||||
foreach ($clients as $client) {
|
||||
$this->climate->out("[$client->id] $client->name");
|
||||
$output->out("[$client->id] $client->name");
|
||||
}
|
||||
|
||||
$input = $this->climate->input('Enter the client ID to associate the new user with: ');
|
||||
$input->accept(
|
||||
$clients->pluck('id')->toArray()
|
||||
);
|
||||
$question = new QuestionInput('Enter the client ID to associate the new user with: ');
|
||||
$question->setAutocompleterValues($clients->pluck('id')->toArray());
|
||||
|
||||
$id = $input->prompt();
|
||||
/** @var QuestionHelper $helper */
|
||||
$helper = $this->getHelper('question');
|
||||
$id = $helper->ask($input, $output, $question);
|
||||
|
||||
$client = Client::find($id);
|
||||
if (!$client) {
|
||||
$this->climate->error('Client not found.');
|
||||
return 1;
|
||||
$output->error('Client not found.');
|
||||
return SCommand::FAILURE;
|
||||
}
|
||||
|
||||
$this->climate->info("Adding a new user for client: $client->name");
|
||||
$output->info("Adding a new user for client: $client->name");
|
||||
$emailQuestion = new QuestionInput('Enter the user\'s email: ');
|
||||
$emailQuestion->setValidator(function ($input): string {
|
||||
if (empty($input) || !filter_var($input, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \InvalidArgumentException('Invalid email address.');
|
||||
}
|
||||
|
||||
$input = $this->climate->input('Enter the user\'s email:');
|
||||
$email = $input->prompt();
|
||||
return $input;
|
||||
});
|
||||
|
||||
$email = $helper->ask($input, $output, $emailQuestion);
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
if ($user) {
|
||||
$this->climate->error('A user with this email already exists. Associating the user with the client.');
|
||||
$output->yellow('A user with this email already exists. Associating the user with the client.');
|
||||
$clientUser = new ClientUser();
|
||||
$clientUser->client_id = $client->id;
|
||||
$clientUser->user_id = $user->id;
|
||||
$clientUser->save();
|
||||
|
||||
return 0;
|
||||
return SCommand::SUCCESS;
|
||||
}
|
||||
|
||||
$passwordInput = $this->climate->password('Enter the user\'s password: 🔐');
|
||||
$password = $passwordInput->prompt();
|
||||
$passwordQuestion = new QuestionInput('Enter the user\'s password: ');
|
||||
$passwordQuestion->setHidden(true);
|
||||
$passwordQuestion->setHiddenFallback(false);
|
||||
$password = $helper->ask($input, $output, $passwordQuestion);
|
||||
|
||||
$firstNameInput = $this->climate->input('Enter the user\'s first name: ');
|
||||
$firstName = $firstNameInput->prompt();
|
||||
$firstNameQuestion = new QuestionInput('Enter the user\'s first name: ');
|
||||
$firstName = $helper->ask($input, $output, $firstNameQuestion);
|
||||
|
||||
$lastNameInput = $this->climate->input('Enter the user\'s last name: ');
|
||||
$lastName = $lastNameInput->prompt();
|
||||
$lastNameQuestion = new QuestionInput('Enter the user\'s last name: ');
|
||||
$lastName = $helper->ask($input, $output, $lastNameQuestion);
|
||||
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
@@ -75,6 +85,8 @@ class Add extends Command
|
||||
$clientUser->user_id = $user->id;
|
||||
$clientUser->save();
|
||||
|
||||
return 0;
|
||||
$output->green('User added and associated with the client successfully.');
|
||||
|
||||
return SCommand::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user