php artisan app:generate-register-token
This commit is contained in:
35
app/Console/Commands/GenerateRegisterToken.php
Normal file
35
app/Console/Commands/GenerateRegisterToken.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\RegisterToken;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Nette\Utils\Random;
|
||||
|
||||
#[Signature('app:generate-register-token')]
|
||||
#[Description('Generate a register token for the internal authentication platform.')]
|
||||
class GenerateRegisterToken extends Command
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$newToken = Random::generate(12, "0-9A-Z");
|
||||
|
||||
try {
|
||||
$rt = new RegisterToken;
|
||||
$rt->token = $newToken;
|
||||
$rt->save();
|
||||
} catch (\ErrorException $e) {
|
||||
$this->error($e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
$this->info("Register token generated: \n" . $newToken);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user