@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
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:create-platform-admin {--name=} {--email=}')]
|
||||
#[Description('Create the first platform-level super administrator')]
|
||||
class CreatePlatformAdmin extends Command
|
||||
{
|
||||
public function handle(): int
|
||||
{
|
||||
if (config('deployment.mode') === 'self_hosted') {
|
||||
$this->error('Platform Super Admin hanya dibuat pada RADIQ control plane atau managed cloud.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$name = $this->option('name') ?: $this->ask('Full name');
|
||||
$email = $this->option('email') ?: $this->ask('Email address');
|
||||
$password = $this->secret('Password (minimum 12 characters)');
|
||||
$confirmation = $this->secret('Confirm password');
|
||||
|
||||
$validator = Validator::make(
|
||||
compact('name', 'email', 'password') + ['password_confirmation' => $confirmation],
|
||||
[
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'max:255', 'unique:users,email'],
|
||||
'password' => ['required', 'confirmed', Password::min(12)->mixedCase()->numbers()->symbols()],
|
||||
],
|
||||
);
|
||||
|
||||
if ($validator->fails()) {
|
||||
foreach ($validator->errors()->all() as $error) {
|
||||
$this->error($error);
|
||||
}
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$admin = new User;
|
||||
$admin->forceFill([
|
||||
'tenant_id' => null,
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'email_verified_at' => now(),
|
||||
'password' => $password,
|
||||
'is_platform_admin' => true,
|
||||
'is_active' => true,
|
||||
])->save();
|
||||
|
||||
$this->info('Platform Master Admin created successfully.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user