Files
hado/core/app/Console/Commands/SourceCreate.php
2026-09-04 06:58:03 -03:00

32 lines
1018 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Console\Commands;
use App\Models\Source;
use Illuminate\Console\Command;
class SourceCreate extends Command
{
protected $signature = 'hado:source:create {name : Имя источника, напр. docs}';
protected $description = 'Регистрирует сервис-клиент и печатает его токен (один раз)';
public function handle(): int
{
$name = (string) $this->argument('name');
if (Source::where('name', $name)->exists()) {
$this->error("Источник «{$name}» уже существует");
return self::FAILURE;
}
$token = 'hado_'.bin2hex(random_bytes(32));
Source::create(['name' => $name, 'token_hash' => hash('sha256', $token)]);
$this->info("Источник «{$name}» создан. Токен показывается один раз, в базе только хэш.");
$this->line("Token: {$token}");
return self::SUCCESS;
}
}