2023-05-03 10:38:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\PrivateKey;
|
|
|
|
|
|
|
|
use App\Models\PrivateKey;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Change extends Component
|
|
|
|
{
|
2023-05-03 12:24:18 +00:00
|
|
|
public string $private_key_uuid;
|
|
|
|
public PrivateKey $private_key;
|
2023-05-03 10:38:57 +00:00
|
|
|
|
2023-05-03 12:24:18 +00:00
|
|
|
protected $rules = [
|
|
|
|
'private_key.name' => 'required|string',
|
|
|
|
'private_key.description' => 'nullable|string',
|
|
|
|
'private_key.private_key' => 'required|string'
|
|
|
|
];
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->private_key = PrivateKey::where('uuid', $this->private_key_uuid)->first();
|
|
|
|
}
|
2023-05-04 13:45:53 +00:00
|
|
|
public function delete()
|
2023-05-03 10:38:57 +00:00
|
|
|
{
|
2023-05-04 13:45:53 +00:00
|
|
|
PrivateKey::where('uuid', $this->private_key_uuid)->delete();
|
2023-05-03 10:38:57 +00:00
|
|
|
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
|
|
|
redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
public function changePrivateKey()
|
|
|
|
{
|
|
|
|
try {
|
2023-05-03 12:24:18 +00:00
|
|
|
$this->private_key->private_key = trim($this->private_key->private_key);
|
|
|
|
if (!str_ends_with($this->private_key->private_key, "\n")) {
|
|
|
|
$this->private_key->private_key .= "\n";
|
2023-05-03 10:38:57 +00:00
|
|
|
}
|
2023-05-03 12:24:18 +00:00
|
|
|
$this->private_key->save();
|
2023-05-03 10:38:57 +00:00
|
|
|
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
|
|
|
} catch (\Exception $e) {
|
2023-05-24 12:26:50 +00:00
|
|
|
return general_error_handler($e, $this);
|
2023-05-03 10:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|