feat: source tokens and client events API
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
31
core/app/Console/Commands/SourceCreate.php
Normal file
31
core/app/Console/Commands/SourceCreate.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user