59 lines
2.4 KiB
PHP
59 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Services\TenantProvisioningService;
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
#[Signature('app:install-tenant {--name=} {--slug=} {--admin-name=} {--admin-email=} {--domain=}')]
|
|
#[Description('Provision the only Tenant Admin account for a self-hosted installation')]
|
|
class InstallTenant extends Command
|
|
{
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(TenantProvisioningService $service): int
|
|
{
|
|
if (config('deployment.mode') !== 'self_hosted') {
|
|
$this->error('Command ini hanya boleh digunakan saat DEPLOYMENT_MODE=self_hosted.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
if (Tenant::exists()) {
|
|
$this->error('Instalasi self-hosted ini sudah memiliki tenant.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
$data = [
|
|
'name' => $this->option('name') ?: $this->ask('Nama tenant/ISP'),
|
|
'slug' => $this->option('slug') ?: $this->ask('Slug tenant'),
|
|
'owner_name' => $this->option('admin-name') ?: $this->ask('Nama Tenant Admin'),
|
|
'owner_email' => $this->option('admin-email') ?: $this->ask('Email Tenant Admin'),
|
|
'owner_password' => $this->secret('Password Tenant Admin (minimum 12 karakter)'),
|
|
'deployment_type' => 'self_hosted', 'deployment_domain' => $this->option('domain'),
|
|
];
|
|
$confirmation = $this->secret('Konfirmasi password Tenant Admin');
|
|
$validator = Validator::make($data + ['owner_password_confirmation' => $confirmation], [
|
|
'name' => ['required', 'string', 'max:255'], 'slug' => ['required', 'alpha_dash', 'max:100'],
|
|
'owner_name' => ['required', 'string', 'max:255'], 'owner_email' => ['required', 'email'],
|
|
'owner_password' => ['required', 'confirmed', Password::min(12)->mixedCase()->numbers()->symbols()],
|
|
]);
|
|
if ($validator->fails()) {
|
|
foreach ($validator->errors()->all() as $error) {
|
|
$this->error($error);
|
|
}
|
|
|
|
return self::FAILURE;
|
|
}
|
|
$service->createWithOwner($data);
|
|
$this->info('RADIQ NDM self-hosted berhasil dipasang. Hanya akun Tenant Admin yang dibuat.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|