116 lines
3.2 KiB
PHP
116 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\ComplianceTools\Livewire\Client;
|
|
|
|
use App\Livewire\Component;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Lang;
|
|
use Paymenter\Extensions\Others\ComplianceTools\Models\AccountDeletionRequest;
|
|
use Paymenter\Extensions\Others\ComplianceTools\Models\SupportPin;
|
|
use Paymenter\Extensions\Others\ComplianceTools\Services\AccountDeletionService;
|
|
use Paymenter\Extensions\Others\ComplianceTools\Services\SupportPinService;
|
|
|
|
class PrivacyCenter extends Component
|
|
{
|
|
public ?AccountDeletionRequest $deletionRequest = null;
|
|
|
|
public ?SupportPin $activePin = null;
|
|
|
|
public string $reason = '';
|
|
|
|
public ?string $generatedPin = null;
|
|
|
|
public bool $showGeneratedPin = false;
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$this->deletionRequest = AccountDeletionRequest::query()
|
|
->where('user_id', $user->getKey())
|
|
->latest()
|
|
->first();
|
|
|
|
$this->activePin = SupportPin::query()
|
|
->where('user_id', $user->getKey())
|
|
->whereNull('revoked_at')
|
|
->where('expires_at', '>', now())
|
|
->latest()
|
|
->first();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('compliance-tools::client.privacy-center')->layoutData([
|
|
'sidebar' => true,
|
|
'title' => Lang::get('compliance-tools::client.title'),
|
|
]);
|
|
}
|
|
|
|
public function submitDeletionRequest(AccountDeletionService $service): void
|
|
{
|
|
if ($this->deletionRequest && $this->deletionRequest->status === AccountDeletionRequest::STATUS_PENDING) {
|
|
$this->notify(Lang::get('compliance-tools::client.deletion_request_exists'), 'warning');
|
|
|
|
return;
|
|
}
|
|
|
|
$user = Auth::user();
|
|
|
|
$this->deletionRequest = $service->submit($user, $this->reason, [
|
|
'ip_address' => request()->ip(),
|
|
'user_agent' => request()->userAgent(),
|
|
]);
|
|
|
|
$this->reason = '';
|
|
|
|
$this->notify(Lang::get('compliance-tools::client.deletion_requested'));
|
|
}
|
|
|
|
public function generatePin(SupportPinService $service): void
|
|
{
|
|
$user = Auth::user();
|
|
|
|
[$pin, $plain] = $service->generate($user);
|
|
|
|
$this->activePin = $pin;
|
|
$this->generatedPin = $plain;
|
|
$this->showGeneratedPin = false;
|
|
|
|
$this->notify(Lang::get('compliance-tools::client.pin_generated'));
|
|
}
|
|
|
|
public function revokePin(SupportPinService $service): void
|
|
{
|
|
if (!$this->activePin) {
|
|
return;
|
|
}
|
|
|
|
$service->revoke($this->activePin, Auth::user());
|
|
|
|
$this->activePin = null;
|
|
$this->generatedPin = null;
|
|
$this->showGeneratedPin = false;
|
|
|
|
$this->notify(Lang::get('compliance-tools::client.pin_revoked'));
|
|
}
|
|
|
|
public function toggleGeneratedPinVisibility(): void
|
|
{
|
|
if (!$this->generatedPin) {
|
|
return;
|
|
}
|
|
|
|
$this->showGeneratedPin = !$this->showGeneratedPin;
|
|
}
|
|
|
|
public function pinCopied(): void
|
|
{
|
|
if (!$this->generatedPin) {
|
|
return;
|
|
}
|
|
|
|
$this->notify(Lang::get('compliance-tools::client.pin_copied'));
|
|
}
|
|
}
|