Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
32 lines
1018 B
PHP
32 lines
1018 B
PHP
<?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;
|
||
}
|
||
}
|