This commit is contained in:
Andras Bacsai
2023-06-07 16:47:10 +02:00
parent 6e084db3d9
commit 0f18fbc24c
6 changed files with 88 additions and 54 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class Create extends Component
@@ -12,22 +11,34 @@ class Create extends Component
public string $name;
public string|null $description = null;
public string $value;
protected $rules = [
'name' => 'required|string',
'value' => 'required|string',
];
protected $validationAttributes = [
'name' => 'Name',
'value' => 'Private Key',
];
public function createPrivateKey()
{
$this->value = trim($this->value);
if (!str_ends_with($this->value, "\n")) {
$this->value .= "\n";
$this->validate();
try {
$this->value = trim($this->value);
if (!str_ends_with($this->value, "\n")) {
$this->value .= "\n";
}
$private_key = PrivateKey::create([
'name' => $this->name,
'description' => $this->description,
'private_key' => $this->value,
'team_id' => session('currentTeam')->id
]);
if ($this->from === 'server') {
return redirect()->route('server.create');
}
return redirect()->route('private-key.show', ['private_key_uuid' => $private_key->uuid]);
} catch (\Exception $e) {
return general_error_handler($e, $this);
}
$private_key = PrivateKey::create([
'name' => $this->name,
'description' => $this->description,
'private_key' => $this->value,
'team_id' => session('currentTeam')->id
]);
if ($this->from === 'server') {
return redirect()->route('server.create');
}
return redirect()->route('private-key.show', ['private_key_uuid' => $private_key->uuid]);
}
}