feat: menric

This commit is contained in:
hashbro
2026-09-06 03:55:24 +08:00
parent f94def7c1f
commit d4c096ed4a
50 changed files with 1698 additions and 148 deletions
@@ -30,6 +30,19 @@ trait PortalAware
return $user;
}
/** @return array{0: string|null, 1: int|null} */
protected function viewerActor(): array
{
if ($this->isAgentPortal()) {
$agent = $this->agent();
return $agent ? ['agent', (int) $agent->id] : [null, null];
}
$admin = auth('admin')->user();
return $admin ? ['admin', (int) $admin->id] : [null, null];
}
protected function routeName(string $suffix): string
{
return $this->portal().'.'.$suffix;
@@ -0,0 +1,46 @@
<?php
namespace App\Http\Controllers\Concerns;
use App\Models\Admin;
use App\Models\User;
use App\Models\WalletMnemonic;
trait RevealsMnemonics
{
protected function canRevealMnemonics(): bool
{
if ($this->isAgentPortal()) {
$agent = $this->agent();
return $agent instanceof User && $agent->canRevealMnemonics();
}
$admin = auth('admin')->user();
return $admin instanceof Admin && $admin->canRevealMnemonics();
}
protected function googleBoundForReveal(): bool
{
if ($this->isAgentPortal()) {
$agent = $this->agent();
return $agent instanceof User && $agent->hasGoogleBound();
}
$admin = auth('admin')->user();
return $admin instanceof Admin && $admin->hasGoogleBound();
}
protected function mnemonicRevealUrl(int|string|WalletMnemonic $mnemonic): string
{
return route($this->portal().'.mnemonics.reveal', $mnemonic);
}
protected function google2faUrl(): string
{
return route($this->portal().'.security.google2fa');
}
}