Add NIP-05 handle management: Introduce migration, API route, and Livewire updates to support NIP-05 handle verification.

 Enhance Nostr fetcher: Refactor profile data merging logic for improved efficiency and accuracy.
🛠
This commit is contained in:
HolgerHatGarKeineNode
2026-01-20 13:56:50 +01:00
parent a857e54d61
commit 34f8d949d5
11 changed files with 669 additions and 106 deletions

0
.ai/mcp/mcp.json Normal file
View File

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\EinundzwanzigPleb;
use Illuminate\Http\Request;
class GetPaidMembers extends Controller
{
public function __invoke($year, Request $request)
{
$paidMembers = EinundzwanzigPleb::query()
->whereHas('paymentEvents', function ($query) use ($year) {
$query->where('year', $year)
->where('paid', true);
})
->select('id', 'npub', 'pubkey', 'nip05_handle')
->get();
return response()->json($paidMembers);
}
}

View File

@@ -2,9 +2,17 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class PaymentEvent extends Model class PaymentEvent extends Model
{ {
use HasFactory;
protected $guarded = []; protected $guarded = [];
public function pleb()
{
return $this->belongsTo(EinundzwanzigPleb::class, 'einundzwanzig_pleb_id');
}
} }

View File

@@ -30,7 +30,6 @@ trait NostrFetcherTrait
'npub' => $item, 'npub' => $item,
]); ]);
} }
$subscription = new Subscription; $subscription = new Subscription;
$subscriptionId = $subscription->setId(); $subscriptionId = $subscription->setId();
@@ -41,13 +40,14 @@ trait NostrFetcherTrait
$requestMessage = new RequestMessage($subscriptionId, $filters); $requestMessage = new RequestMessage($subscriptionId, $filters);
$relayUrls = [ $relayUrls = [
'wss://relay.primal.net',
'wss://purplepag.es', 'wss://purplepag.es',
'wss://nostr.wine', 'wss://nostr.wine',
'wss://relay.damus.io', 'wss://relay.damus.io',
'wss://relay.primal.net',
]; ];
$data = null; // Collect all responses from all relays
$allResponses = collect([]);
foreach ($relayUrls as $relayUrl) { foreach ($relayUrls as $relayUrl) {
$relay = new Relay($relayUrl); $relay = new Relay($relayUrl);
$relay->setMessage($requestMessage); $relay->setMessage($requestMessage);
@@ -57,25 +57,30 @@ trait NostrFetcherTrait
$data = $response[$relayUrl]; $data = $response[$relayUrl];
if (! empty($data)) { if (! empty($data)) {
\Log::info('Successfully fetched data from relay: '.$relayUrl); \Log::info('Successfully fetched data from relay: '.$relayUrl);
break; // Exit the loop if data is not empty $allResponses = $allResponses->concat($data);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
\Log::warning('Failed to fetch from relay '.$relayUrl.': '.$e->getMessage()); \Log::warning('Failed to fetch from relay '.$relayUrl.': '.$e->getMessage());
} }
} }
if (empty($data)) { if ($allResponses->isEmpty()) {
\Log::warning('No data found from any relay'); \Log::warning('No data found from any relay');
return; return;
} }
foreach ($data as $item) {
// Group responses by pubkey and merge profile data
$mergedProfiles = [];
foreach ($allResponses as $item) {
try { try {
if (isset($item->event)) { if (isset($item->event)) {
$pubkey = $item->event->pubkey;
$result = json_decode($item->event->content, true, 512, JSON_THROW_ON_ERROR); $result = json_decode($item->event->content, true, 512, JSON_THROW_ON_ERROR);
Profile::query()->updateOrCreate(
['pubkey' => $item->event->pubkey], if (! isset($mergedProfiles[$pubkey])) {
[ $mergedProfiles[$pubkey] = [
'pubkey' => $pubkey,
'name' => $result['name'] ?? null, 'name' => $result['name'] ?? null,
'display_name' => $result['display_name'] ?? null, 'display_name' => $result['display_name'] ?? null,
'picture' => $result['picture'] ?? null, 'picture' => $result['picture'] ?? null,
@@ -86,13 +91,36 @@ trait NostrFetcherTrait
'lud16' => $result['lud16'] ?? null, 'lud16' => $result['lud16'] ?? null,
'lud06' => $result['lud06'] ?? null, 'lud06' => $result['lud06'] ?? null,
'deleted' => $result['deleted'] ?? false, 'deleted' => $result['deleted'] ?? false,
], ];
); } else {
\Log::info('Profile updated/created for pubkey: '.$item->event->pubkey); // Merge data: keep existing non-null values, use new values if existing is null
$fields = ['name', 'display_name', 'picture', 'banner', 'website', 'about', 'nip05', 'lud16', 'lud06', 'deleted'];
foreach ($fields as $field) {
if (array_key_exists($field, $result)) {
$mergedProfiles[$pubkey][$field] = $result[$field];
}
}
}
} }
} catch (\JsonException $e) { } catch (\JsonException $e) {
\Log::error('Error decoding JSON: '.$e->getMessage()); \Log::error('Error decoding JSON for pubkey: '.$item->event->pubkey ?? 'unknown', [
throw new \RuntimeException('Error decoding JSON: '.$e->getMessage()); 'error' => $e->getMessage(),
]);
}
}
// Update/create profiles with merged data
foreach ($mergedProfiles as $profileData) {
try {
Profile::query()->updateOrCreate(
['pubkey' => $profileData['pubkey']],
$profileData,
);
\Log::info('Profile updated/created for pubkey: '.$profileData['pubkey']);
} catch (\Exception $e) {
\Log::error('Failed to save profile for pubkey: '.$profileData['pubkey'], [
'error' => $e->getMessage(),
]);
} }
} }
} }

View File

@@ -0,0 +1,37 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PaymentEvent>
*/
class PaymentEventFactory extends Factory
{
public function definition(): array
{
return [
'einundzwanzig_pleb_id' => \App\Models\EinundzwanzigPleb::factory(),
'year' => fake()->year(),
'event_id' => fake()->uuid(),
'amount' => 21000,
'paid' => false,
'btc_pay_invoice' => null,
];
}
public function paid(): self
{
return $this->state(fn (array $attributes) => [
'paid' => true,
]);
}
public function withYear(int $year): self
{
return $this->state(fn (array $attributes) => [
'year' => $year,
]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('einundzwanzig_plebs', function (Blueprint $table) {
$table->string('nip05_handle')->nullable()->unique();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('einundzwanzig_plebs', function (Blueprint $table) {
$table->dropUnique(['nip05_handle']);
$table->dropColumn('nip05_handle');
});
}
};

View File

@@ -114,8 +114,6 @@ class extends Component {
<div> <div>
@if($isAllowed) @if($isAllowed)
<div class="px-4 sm:px-6 lg:px-8 py-8 md:py-0 w-full max-w-9xl mx-auto">
<div class="xl:flex"> <div class="xl:flex">
<!-- Left + Middle content --> <!-- Left + Middle content -->
@@ -344,10 +342,8 @@ class extends Component {
</div> </div>
</div> </div>
</div>
@else @else
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto"> <div class="">
<flux:callout variant="warning" icon="exclamation-circle"> <flux:callout variant="warning" icon="exclamation-circle">
<flux:heading>Zugriff auf News nicht möglich</flux:heading> <flux:heading>Zugriff auf News nicht möglich</flux:heading>
<p>Um die News einzusehen, benötigst du:</p> <p>Um die News einzusehen, benötigst du:</p>

View File

@@ -16,8 +16,7 @@ use swentel\nostr\Request\Request;
use swentel\nostr\Sign\Sign; use swentel\nostr\Sign\Sign;
use swentel\nostr\Subscription\Subscription; use swentel\nostr\Subscription\Subscription;
new class extends Component new class extends Component {
{
public ApplicationForm $form; public ApplicationForm $form;
public bool $no = false; public bool $no = false;
@@ -28,13 +27,15 @@ new class extends Component
public ?string $email = ''; public ?string $email = '';
public ?string $nip05Handle = '';
public array $yearsPaid = []; public array $yearsPaid = [];
public array $events = []; public array $events = [];
public $payments; public $payments;
public int $amountToPay; public int $amountToPay = 21000;
public bool $currentYearIsPaid = false; public bool $currentYearIsPaid = false;
@@ -55,16 +56,19 @@ new class extends Component
$this->currentPubkey = NostrAuth::pubkey(); $this->currentPubkey = NostrAuth::pubkey();
$this->currentPleb = EinundzwanzigPleb::query() $this->currentPleb = EinundzwanzigPleb::query()
->with([ ->with([
'paymentEvents' => fn ($query) => $query->where('year', date('Y')), 'paymentEvents' => fn($query) => $query->where('year', date('Y')),
'profile',
]) ])
->where('pubkey', $this->currentPubkey)->first(); ->where('pubkey', $this->currentPubkey)->first();
if ($this->currentPleb) { if ($this->currentPleb) {
$this->email = $this->currentPleb->email; $this->email = $this->currentPleb->email;
$this->no = $this->currentPleb->no_email; if ($this->currentPleb->nip05_handle) {
$this->showEmail = ! $this->no; $this->nip05Handle = strtolower(str_replace('@einundzwanzig.space', '',
if ($this->currentPleb->association_status === AssociationStatus::ACTIVE) { $this->currentPleb->nip05_handle));
$this->amountToPay = config('app.env') === 'production' ? 21000 : 1;
} }
$this->no = $this->currentPleb->no_email;
$this->showEmail = !$this->no;
$this->amountToPay = config('app.env') === 'production' ? 21000 : 1;
if ($this->currentPleb->paymentEvents->count() < 1) { if ($this->currentPleb->paymentEvents->count() < 1) {
$this->createPaymentEvent(); $this->createPaymentEvent();
$this->currentPleb->load('paymentEvents'); $this->currentPleb->load('paymentEvents');
@@ -77,7 +81,7 @@ new class extends Component
public function updatedNo(): void public function updatedNo(): void
{ {
$this->showEmail = ! $this->no; $this->showEmail = !$this->no;
$this->currentPleb->update([ $this->currentPleb->update([
'no_email' => $this->no, 'no_email' => $this->no,
]); ]);
@@ -88,6 +92,11 @@ new class extends Component
$this->js('alert("Markus Turm wird sich per Fax melden!")'); $this->js('alert("Markus Turm wird sich per Fax melden!")');
} }
public function updatedNip05Handle(): void
{
$this->nip05Handle = strtolower($this->nip05Handle);
}
public function saveEmail(): void public function saveEmail(): void
{ {
$this->validate([ $this->validate([
@@ -99,6 +108,20 @@ new class extends Component
Flux::toast('E-Mail Adresse gespeichert.'); Flux::toast('E-Mail Adresse gespeichert.');
} }
public function saveNip05Handle(): void
{
$this->validate([
'nip05Handle' => 'required|string|max:255|regex:/^[a-z0-9_-]+$/|unique:einundzwanzig_plebs,nip05_handle',
]);
$nip05Handle = strtolower($this->nip05Handle).'@einundzwanzig.space';
$this->currentPleb->update([
'nip05_handle' => $nip05Handle,
]);
Flux::toast('NIP-05 Handle gespeichert.');
}
public function pay($comment): mixed public function pay($comment): mixed
{ {
$paymentEvent = $this->currentPleb $paymentEvent = $this->currentPleb
@@ -184,7 +207,7 @@ new class extends Component
public function save($type): void public function save($type): void
{ {
$this->form->validate(); $this->form->validate();
if (! $this->form->check) { if (!$this->form->check) {
$this->js('alert("Du musst den Statuten zustimmen.")'); $this->js('alert("Du musst den Statuten zustimmen.")');
return; return;
@@ -249,7 +272,7 @@ new class extends Component
$this->events = collect($response[config('services.relay')]) $this->events = collect($response[config('services.relay')])
->map(function ($event) { ->map(function ($event) {
if (! isset($event->event)) { if (!isset($event->event)) {
return false; return false;
} }
@@ -270,7 +293,6 @@ new class extends Component
?> ?>
<div> <div>
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-7xl mx-auto">
<!-- Header --> <!-- Header -->
<div class="mb-8"> <div class="mb-8">
<h1 class="text-2xl md:text-3xl text-[#1B1B1B] dark:text-gray-100 font-bold"> <h1 class="text-2xl md:text-3xl text-[#1B1B1B] dark:text-gray-100 font-bold">
@@ -278,14 +300,187 @@ new class extends Component
</h1> </h1>
</div> </div>
<div class="flex gap-6">
<!-- Membership Benefits Section -->
<flux:card class="w-1/3">
<div class="flex max-md:flex-col items-start">
<div class="flex-1 max-md:pt-6 self-stretch">
<flux:heading size="xl" level="1">Vorteile deiner Mitgliedschaft</flux:heading>
<flux:separator variant="subtle" class="mb-6"/>
<!-- Benefits Grid -->
<div class="grid grid-cols-1 gap-4">
<!-- Benefit 1 -->
<div
class="bg-linear-to-br from-amber-50 to-orange-50 dark:from-amber-300/10 dark:to-orange-900/10 rounded-lg p-4 border border-amber-200 dark:border-amber-200/30">
<div class="flex items-start gap-3">
<div class="shrink-0">
<div
class="w-8 h-8 rounded-full bg-amber-100 dark:bg-amber-900/60 flex items-center justify-center">
<i class="fa-sharp-duotone fa-solid fa-bolt text-amber-600 dark:text-amber-400 text-base"></i>
</div>
</div>
<div class="flex-1 min-w-0">
<h3 class="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-1">
Nostr Relay
</h3>
<p class="text-sm text-gray-600 dark:text-gray-400">
Exklusive Schreib-Rechte auf Premium Nostr Relay von Einundzwanzig.
</p>
</div>
</div>
</div>
<!-- Benefit 2: NIP-05 -->
<div
class="bg-linear-to-br from-emerald-50 to-teal-50 dark:from-emerald-300/10 dark:to-teal-900/10 rounded-lg p-4 border border-emerald-200 dark:border-emerald-200/30">
<div class="flex items-start gap-3 mb-3">
<div class="shrink-0">
<div
class="w-8 h-8 rounded-full bg-emerald-100 dark:bg-emerald-900/60 flex items-center justify-center">
<i class="fa-sharp-duotone fa-solid fa-check-circle text-emerald-600 dark:text-emerald-400 text-base"></i>
</div>
</div>
<div class="flex-1 min-w-0">
<h3 class="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-1">
Get NIP-05 verified
</h3>
<p class="text-sm text-gray-600 dark:text-gray-400">
Verifiziere deine Identität mit einem menschenlesbaren Nostr-Namen.
</p>
</div>
</div>
<!-- NIP-05 Input -->
@if($currentPleb && $currentPleb->association_status->value > 1 && $currentYearIsPaid)
<div class="space-y-3">
<flux:field>
<flux:label>Dein NIP-05 Handle</flux:label>
<flux:input.group>
<flux:input
wire:model.live.debounce="nip05Handle"
placeholder="dein-name"
/>
<flux:input.group.suffix>@einundzwanzig.space</flux:input.group.suffix>
</flux:input.group>
<flux:error name="nip05Handle"/>
</flux:field>
<div class="flex gap-3">
<flux:button
wire:click="saveNip05Handle"
wire:loading.attr="disabled"
size="sm"
variant="primary">
Speichern
</flux:button>
</div>
<!-- Rules Info -->
<div
class="mt-3 p-3 bg-white/50 dark:bg-gray-800/50 rounded border border-gray-200 dark:border-gray-600">
<p class="text-xs text-gray-600 dark:text-gray-400 leading-relaxed">
<strong>Regeln für dein Handle:</strong> Nur Kleinbuchstaben (a-z), Zahlen
(0-9) und die Zeichen "-" und "_" sind erlaubt. Dein Handle wird automatisch
kleingeschrieben.
</p>
</div>
<!-- Explanation -->
<div
class="mt-4 p-3 bg-white/50 dark:bg-gray-800/50 rounded border border-gray-200 dark:border-gray-600">
<p class="text-xs text-gray-600 dark:text-gray-400 leading-relaxed">
<flux:link href="https://nostr.how/en/guides/get-verified#self-hosted"
target="_blank">NIP-05
</flux:link>
verifiziert deine Identität auf Nostr. Das Handle ist wie eine
E-Mail-Adresse (z.B. name@einundzwanzig.space). Clients zeigen ein Häkchen
für verifizierte Benutzer. Dies macht dein Profil einfacher zu teilen und
vertrauenswürdiger.
</p>
</div>
</div>
@else
<div class="text-xs text-gray-500 dark:text-gray-400 italic">
Aktiviere deine Mitgliedschaft, um NIP-05 zu verifizieren.
</div>
@endif
</div>
</div>
<!-- Additional Information -->
<flux:callout variant="success" class="mt-6">
<div class="flex items-start gap-3">
<i class="fa-sharp-duotone fa-solid fa-star text-amber-500 mt-0.5"></i>
<div>
<p class="font-medium text-gray-800 dark:text-gray-100">
Mehr Vorteile kommen bald!
</p>
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
Wir arbeiten ständig daran, unsere Mitglieder-Vorteile auszubauen.
Bleib dran für neue exklusive Services und Kooperationen.
</p>
</div>
</div>
</flux:callout>
</div>
</div>
</flux:card>
<!-- Main Grid Layout --> <!-- Main Grid Layout -->
<div class="grid grid-cols-1 gap-6"> <div class="w-2/3 grid grid-cols-1 gap-6">
@if($currentPleb)
<!-- Logged-in User Info -->
<flux:callout variant="info">
<div class="flex items-start gap-4">
<img
class="w-12 h-12 rounded-full shrink-0 border-2 border-gray-200 dark:border-gray-600"
src="{{ $currentPleb->profile?->picture ?? asset('apple-touch-icon.png') }}"
alt="Avatar"
>
<div class="flex-1 min-w-0">
<div class="mb-2">
<h4 class="font-semibold text-gray-800 dark:text-gray-100 text-base">
{{ $currentPleb->profile?->display_name ?? $currentPleb->profile?->name ?? 'Unbekannt' }}
</h4>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
@if($currentPleb->profile?->name)
{{ $currentPleb->profile->name }}
@endif
</p>
</div>
<div class="space-y-1 text-xs">
<div class="flex items-center gap-2">
<span class="text-gray-500 dark:text-gray-400 shrink-0">Pubkey:</span>
<code
class="bg-gray-100 dark:bg-gray-800 px-2 py-0.5 rounded text-gray-700 dark:text-gray-300 truncate font-mono">
{{ $currentPleb->pubkey }}
</code>
</div>
<div class="flex items-center gap-2">
<span class="text-gray-500 dark:text-gray-400 shrink-0">Npub:</span>
<code
class="bg-gray-100 dark:bg-gray-800 px-2 py-0.5 rounded text-gray-700 dark:text-gray-300 truncate font-mono text-xs">
{{ $currentPleb->npub }}
</code>
</div>
@if($currentPleb->nip05_handle)
<div class="flex items-center gap-2">
<span class="text-gray-500 dark:text-gray-400 shrink-0">NIP-05:</span>
<code
class="bg-gray-100 dark:bg-gray-800 px-2 py-0.5 rounded text-gray-700 dark:text-gray-300 font-mono text-xs">
{{ $currentPleb->nip05_handle }}
</code>
</div>
@endif
</div>
</div>
</div>
</flux:callout>
@endif
<!-- Status Section --> <!-- Status Section -->
<flux:card> <flux:card>
<h2 class="text-xl md:text-2xl text-[#1B1B1B] dark:text-gray-100 font-bold mb-6">
Aktueller Status
</h2>
@if(!$currentPleb) @if(!$currentPleb)
<!-- Nostr Login Apps Section --> <!-- Nostr Login Apps Section -->
<div class="space-y-4 mb-8"> <div class="space-y-4 mb-8">
@@ -296,14 +491,16 @@ new class extends Component
<!-- Grid of App Cards --> <!-- Grid of App Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<flux:card> <flux:card>
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4"> <div
class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div class="flex-1"> <div class="flex-1">
<a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors" <a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors"
href="https://github.com/greenart7c3/Amber"> href="https://github.com/greenart7c3/Amber">
Amber Amber
</a> </a>
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1"> <p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
Perfekt für mobile Android Geräte. Eine App, in der man alle Keys/nsecs verwalten kann. Perfekt für mobile Android Geräte. Eine App, in der man alle Keys/nsecs
verwalten kann.
</p> </p>
</div> </div>
<div class="shrink-0"> <div class="shrink-0">
@@ -313,14 +510,16 @@ new class extends Component
</flux:card> </flux:card>
<flux:card> <flux:card>
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4"> <div
class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div class="flex-1"> <div class="flex-1">
<a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors" <a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors"
href="https://addons.mozilla.org/en-US/firefox/addon/alby/"> href="https://addons.mozilla.org/en-US/firefox/addon/alby/">
Alby - Bitcoin Lightning Wallet & Nostr Alby - Bitcoin Lightning Wallet & Nostr
</a> </a>
<p class="text-sm text-gray-600 dark:text-gray-400 mt-1"> <p class="text-sm text-gray-600 dark:text-gray-400 mt-1">
Browser-Erweiterung in die man seinen Key/nsec eingeben kann. Pro Alby-Konto ein nsec. Browser-Erweiterung in die man seinen Key/nsec eingeben kann. Pro Alby-Konto
ein nsec.
</p> </p>
</div> </div>
<div class="shrink-0"> <div class="shrink-0">
@@ -330,7 +529,8 @@ new class extends Component
</flux:card> </flux:card>
<flux:card> <flux:card>
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4"> <div
class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div class="flex-1"> <div class="flex-1">
<a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors" <a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors"
href="https://chromewebstore.google.com/detail/nos2x/kpgefcfmnafjgpblomihpgmejjdanjjp"> href="https://chromewebstore.google.com/detail/nos2x/kpgefcfmnafjgpblomihpgmejjdanjjp">
@@ -347,7 +547,8 @@ new class extends Component
</flux:card> </flux:card>
<flux:card> <flux:card>
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4"> <div
class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div class="flex-1"> <div class="flex-1">
<a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors" <a class="font-semibold text-gray-800 dark:text-gray-100 hover:text-amber-500 dark:hover:text-amber-400 transition-colors"
href="https://addons.mozilla.org/en-US/firefox/addon/nos2x-fox/"> href="https://addons.mozilla.org/en-US/firefox/addon/nos2x-fox/">
@@ -383,10 +584,13 @@ new class extends Component
@if($currentPubkey && $currentPleb->association_status->value < 2) @if($currentPubkey && $currentPleb->association_status->value < 2)
<flux:card class="mt-4"> <flux:card class="mt-4">
<div class="flex items-start gap-3"> <div class="flex items-start gap-3">
<svg class="shrink-0 fill-current text-green-500 mt-0.5" width="16" height="16" viewBox="0 0 16 16"> <svg class="shrink-0 fill-current text-green-500 mt-0.5" width="16" height="16"
<path d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zM7 11.4L3.6 8 5 6.6l2 2 4-4L12.4 6 7 11.4z"></path> viewBox="0 0 16 16">
<path
d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zM7 11.4L3.6 8 5 6.6l2 2 4-4L12.4 6 7 11.4z"></path>
</svg> </svg>
<p class="text-sm text-gray-700 dark:text-gray-300">Profil in der Datenbank vorhanden.</p> <p class="text-sm text-gray-700 dark:text-gray-300">Profil in der Datenbank
vorhanden.</p>
</div> </div>
</flux:card> </flux:card>
@endif @endif
@@ -396,14 +600,15 @@ new class extends Component
@if($currentPubkey && !$currentPleb->application_for && $currentPleb->association_status->value < 2) @if($currentPubkey && !$currentPleb->application_for && $currentPleb->association_status->value < 2)
<!-- Membership Registration Section --> <!-- Membership Registration Section -->
<div class="space-y-4 py-6 border-t border-gray-200 dark:border-gray-600"> <div class="space-y-4 py-6">
<div> <div>
<h3 class="text-xl md:text-2xl text-[#1B1B1B] dark:text-gray-100 font-bold mb-2"> <h3 class="text-xl md:text-2xl text-[#1B1B1B] dark:text-gray-100 font-bold mb-2">
Einundzwanzig Mitglied werden Einundzwanzig Mitglied werden
</h3> </h3>
<p class="text-sm text-gray-600 dark:text-gray-400"> <p class="text-sm text-gray-600 dark:text-gray-400">
Nur Personen können Mitglied werden und zahlen 21.000 Satoshis im Jahr. Nur Personen können Mitglied werden und zahlen 21.000 Satoshis im Jahr.
<a href="https://einundzwanzig.space/verein/" class="text-amber-500 hover:text-amber-600 dark:hover:text-amber-400 font-medium"> <a href="https://einundzwanzig.space/verein/"
class="text-amber-500 hover:text-amber-600 dark:hover:text-amber-400 font-medium">
Firmen melden sich bitte direkt an den Vorstand. Firmen melden sich bitte direkt an den Vorstand.
</a> </a>
</p> </p>
@@ -418,7 +623,8 @@ new class extends Component
<flux:button wire:click="save({{ AssociationStatus::PASSIVE() }})" variant="primary"> <flux:button wire:click="save({{ AssociationStatus::PASSIVE() }})" variant="primary">
Mit deinem aktuellen Nostr-Profil Mitglied werden Mit deinem aktuellen Nostr-Profil Mitglied werden
</flux:button> </flux:button>
<flux:button href="https://einundzwanzig.space/verein/" target="_blank" variant="outline"> <flux:button href="https://einundzwanzig.space/verein/" target="_blank"
variant="outline">
Statuten ansehen Statuten ansehen
</flux:button> </flux:button>
</div> </div>
@@ -428,14 +634,16 @@ new class extends Component
@if($currentPubkey) @if($currentPubkey)
<!-- Email Settings Section --> <!-- Email Settings Section -->
<div class="py-6 border-t border-gray-200 dark:border-gray-600"> <div class="py-6">
<flux:callout variant="warning" class="mb-6"> <flux:callout variant="warning" class="mb-6">
<div class="space-y-4"> <div class="space-y-4">
<p class="font-medium text-gray-800 dark:text-gray-100"> <p class="font-medium text-gray-800 dark:text-gray-100">
Falls du möchtest, kannst du hier eine E-Mail Adresse hinterlegen, damit der Verein dich darüber informieren kann, wenn es Neuigkeiten gibt. Falls du möchtest, kannst du hier eine E-Mail Adresse hinterlegen, damit der Verein
dich darüber informieren kann, wenn es Neuigkeiten gibt.
</p> </p>
<p class="text-sm text-gray-600 dark:text-gray-400"> <p class="text-sm text-gray-600 dark:text-gray-400">
Am besten eine anonymisierte E-Mail Adresse verwenden. Wir sichern diese Adresse AES-256 verschlüsselt in der Datenbank ab. Am besten eine anonymisierte E-Mail Adresse verwenden. Wir sichern diese Adresse
AES-256 verschlüsselt in der Datenbank ab.
</p> </p>
</div> </div>
</flux:callout> </flux:callout>
@@ -459,7 +667,8 @@ new class extends Component
<flux:field> <flux:field>
<flux:label>E-Mail Adresse</flux:label> <flux:label>E-Mail Adresse</flux:label>
<flux:input type="email" wire:model.live.debounce="email" placeholder="E-Mail Adresse"/> <flux:input type="email" wire:model.live.debounce="email"
placeholder="E-Mail Adresse"/>
<flux:error name="email"/> <flux:error name="email"/>
</flux:field> </flux:field>
</div> </div>
@@ -479,8 +688,10 @@ new class extends Component
@if($currentPleb && $currentPleb->association_status->value > 1) @if($currentPleb && $currentPleb->association_status->value > 1)
<flux:card> <flux:card>
<div class="flex items-start gap-3"> <div class="flex items-start gap-3">
<svg class="shrink-0 fill-current text-green-500 mt-0.5" width="16" height="16" viewBox="0 0 16 16"> <svg class="shrink-0 fill-current text-green-500 mt-0.5" width="16" height="16"
<path d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 12c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1zm1-3H7V4h2v5z"></path> viewBox="0 0 16 16">
<path
d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 12c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1zm1-3H7V4h2v5z"></path>
</svg> </svg>
<div> <div>
<p class="font-medium text-gray-800 dark:text-gray-100"> <p class="font-medium text-gray-800 dark:text-gray-100">
@@ -508,7 +719,8 @@ new class extends Component
<flux:callout variant="info" class="mb-6"> <flux:callout variant="info" class="mb-6">
<p class="text-sm"> <p class="text-sm">
Nostr Event für die Zahlung des Mitgliedsbeitrags: Nostr Event für die Zahlung des Mitgliedsbeitrags:
<span class="block mt-2 font-mono text-xs break-all">{{ $currentPleb->paymentEvents->last()->event_id }}</span> <span
class="block mt-2 font-mono text-xs break-all">{{ $currentPleb->paymentEvents->last()->event_id }}</span>
</p> </p>
</flux:callout> </flux:callout>
@@ -541,7 +753,8 @@ new class extends Component
<div class="flex items-start gap-3"> <div class="flex items-start gap-3">
<i class="fa-sharp-duotone fa-solid fa-user-helmet-safety mt-1"></i> <i class="fa-sharp-duotone fa-solid fa-user-helmet-safety mt-1"></i>
<p class="text-sm"> <p class="text-sm">
Unser Nostr-Relay konnte derzeit nicht erreicht werden, um eine Zahlung zu initialisieren. Bitte versuche es später noch einmal. Unser Nostr-Relay konnte derzeit nicht erreicht werden, um eine Zahlung zu
initialisieren. Bitte versuche es später noch einmal.
</p> </p>
</div> </div>
</flux:callout> </flux:callout>
@@ -558,7 +771,8 @@ new class extends Component
<!-- Desktop Table --> <!-- Desktop Table -->
<div class="hidden md:block overflow-x-auto"> <div class="hidden md:block overflow-x-auto">
<table class="table-auto w-full"> <table class="table-auto w-full">
<thead class="text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 border-b border-gray-200 dark:border-gray-600"> <thead
class="text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 border-b border-gray-200 dark:border-gray-600">
<tr> <tr>
<th class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap text-left"> <th class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap text-left">
<div class="font-semibold">Satoshis</div> <div class="font-semibold">Satoshis</div>
@@ -578,13 +792,16 @@ new class extends Component
@foreach($payments as $payment) @foreach($payments as $payment)
<tr> <tr>
<td class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap"> <td class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap">
<div class="font-medium text-gray-800 dark:text-gray-100">{{ $payment->amount }}</div> <div
class="font-medium text-gray-800 dark:text-gray-100">{{ $payment->amount }}</div>
</td> </td>
<td class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap"> <td class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap">
<div class="text-gray-800 dark:text-gray-100">{{ $payment->year }}</div> <div
class="text-gray-800 dark:text-gray-100">{{ $payment->year }}</div>
</td> </td>
<td class="px-2 first:pl-5 last:pr-5 py-3"> <td class="px-2 first:pl-5 last:pr-5 py-3">
<div class="font-mono text-xs text-gray-600 dark:text-gray-400 break-all">{{ $payment->event_id }}</div> <div
class="font-mono text-xs text-gray-600 dark:text-gray-400 break-all">{{ $payment->event_id }}</div>
</td> </td>
<td class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap"> <td class="px-2 first:pl-5 last:pr-5 py-3 whitespace-nowrap">
@if($payment->btc_pay_invoice) @if($payment->btc_pay_invoice)
@@ -606,19 +823,24 @@ new class extends Component
<!-- Mobile Cards --> <!-- Mobile Cards -->
<div class="md:hidden space-y-4"> <div class="md:hidden space-y-4">
@foreach($payments as $payment) @foreach($payments as $payment)
<div class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-600 p-4"> <div
class="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-600 p-4">
<div class="space-y-3"> <div class="space-y-3">
<div class="flex justify-between items-center"> <div class="flex justify-between items-center">
<span class="text-sm font-medium text-gray-500 dark:text-gray-400">Satoshis</span> <span class="text-sm font-medium text-gray-500 dark:text-gray-400">Satoshis</span>
<span class="font-semibold text-gray-800 dark:text-gray-100">{{ $payment->amount }}</span> <span
class="font-semibold text-gray-800 dark:text-gray-100">{{ $payment->amount }}</span>
</div> </div>
<div class="flex justify-between items-center"> <div class="flex justify-between items-center">
<span class="text-sm font-medium text-gray-500 dark:text-gray-400">Jahr</span> <span class="text-sm font-medium text-gray-500 dark:text-gray-400">Jahr</span>
<span class="text-gray-800 dark:text-gray-100">{{ $payment->year }}</span> <span
class="text-gray-800 dark:text-gray-100">{{ $payment->year }}</span>
</div> </div>
<div> <div>
<span class="text-sm font-medium text-gray-500 dark:text-gray-400 block mb-1">Event-ID</span> <span
<span class="font-mono text-xs text-gray-600 dark:text-gray-400 break-all">{{ $payment->event_id }}</span> class="text-sm font-medium text-gray-500 dark:text-gray-400 block mb-1">Event-ID</span>
<span
class="font-mono text-xs text-gray-600 dark:text-gray-400 break-all">{{ $payment->event_id }}</span>
</div> </div>
@if($payment->btc_pay_invoice) @if($payment->btc_pay_invoice)
<flux:button <flux:button

View File

@@ -1,6 +1,8 @@
<?php <?php
use App\Http\Controllers\Api\GetPaidMembers;
use App\Http\Controllers\Api\Nostr\GetProfile; use App\Http\Controllers\Api\Nostr\GetProfile;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/nostr/profile/{key}', GetProfile::class); Route::get('/nostr/profile/{key}', GetProfile::class);
Route::get('/members/{year}', GetPaidMembers::class);

View File

@@ -0,0 +1,164 @@
<?php
use App\Enums\AssociationStatus;
use App\Models\EinundzwanzigPleb;
use App\Models\PaymentEvent;
beforeEach(function () {
PaymentEvent::query()->delete();
EinundzwanzigPleb::query()->delete();
});
test('returns paid members for a specific year', function () {
$member1 = EinundzwanzigPleb::factory()->create([
'npub' => 'npub1abc',
'pubkey' => 'pubkey1',
'nip05_handle' => 'user1@example.com',
'association_status' => AssociationStatus::ACTIVE,
]);
$member2 = EinundzwanzigPleb::factory()->create([
'npub' => 'npub2def',
'pubkey' => 'pubkey2',
'nip05_handle' => 'user2@example.com',
'association_status' => AssociationStatus::ACTIVE,
]);
$member3 = EinundzwanzigPleb::factory()->create([
'npub' => 'npub3ghi',
'pubkey' => 'pubkey3',
'association_status' => AssociationStatus::ACTIVE,
]);
$year = 2024;
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member1->id,
'year' => $year,
'paid' => true,
]);
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member2->id,
'year' => $year,
'paid' => true,
]);
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member3->id,
'year' => $year,
'paid' => false,
]);
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member1->id,
'year' => 2023,
'paid' => true,
]);
$response = $this->getJson("/api/members/{$year}");
$response->assertStatus(200);
$response->assertJsonCount(2);
$response->assertJsonFragment([
'npub' => 'npub1abc',
'pubkey' => 'pubkey1',
'nip05_handle' => 'user1@example.com',
]);
$response->assertJsonFragment([
'npub' => 'npub2def',
'pubkey' => 'pubkey2',
'nip05_handle' => 'user2@example.com',
]);
$response->assertJsonMissing([
'npub' => 'npub3ghi',
]);
});
test('returns empty array when no members paid for year', function () {
$year = 2024;
$response = $this->getJson("/api/members/{$year}");
$response->assertStatus(200);
$response->assertJson([]);
});
test('only returns npub, pubkey, and nip05_handle fields', function () {
$member = EinundzwanzigPleb::factory()->create([
'npub' => 'npub1abc',
'pubkey' => 'pubkey1',
'nip05_handle' => 'user1@example.com',
'association_status' => AssociationStatus::ACTIVE,
]);
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member->id,
'year' => 2024,
'paid' => true,
]);
$response = $this->getJson('/api/members/2024');
$response->assertStatus(200);
$json = $response->json();
expect($json[0])->toHaveKeys(['id', 'npub', 'pubkey', 'nip05_handle']);
expect($json[0])->not->toHaveKeys([
'email',
'association_status',
'no_email',
'application_for',
]);
});
test('includes nip05_handle in response when available', function () {
$member = EinundzwanzigPleb::factory()->create([
'npub' => 'npub1abc',
'pubkey' => 'pubkey1',
'nip05_handle' => 'verified@example.com',
'association_status' => AssociationStatus::ACTIVE,
]);
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member->id,
'year' => 2024,
'paid' => true,
]);
$response = $this->getJson('/api/members/2024');
$response->assertStatus(200);
$response->assertJsonFragment([
'nip05_handle' => 'verified@example.com',
]);
});
test('nip05_handle is null in response when not set', function () {
$member = EinundzwanzigPleb::factory()->create([
'npub' => 'npub1abc',
'pubkey' => 'pubkey1',
'nip05_handle' => null,
'association_status' => AssociationStatus::ACTIVE,
]);
PaymentEvent::factory()->create([
'einundzwanzig_pleb_id' => $member->id,
'year' => 2024,
'paid' => true,
]);
$response = $this->getJson('/api/members/2024');
$response->assertStatus(200);
$json = $response->json();
expect($json[0]['nip05_handle'])->toBeNull();
});

View File

@@ -49,6 +49,60 @@ it('validates email format', function () {
->assertHasErrors(['email']); ->assertHasErrors(['email']);
}); });
it('can save nip05 handle', function () {
$pleb = EinundzwanzigPleb::factory()->active()->create();
NostrAuth::login($pleb->pubkey);
Livewire::test('association.profile')
->set('nip05Handle', 'user@example.com')
->call('saveNip05Handle')
->assertHasNoErrors();
expect($pleb->fresh()->nip05_handle)->toBe('user@example.com');
});
it('validates nip05 handle format', function () {
$pleb = EinundzwanzigPleb::factory()->active()->create();
NostrAuth::login($pleb->pubkey);
Livewire::test('association.profile')
->set('nip05Handle', 'not-an-email')
->call('saveNip05Handle')
->assertHasErrors(['nip05Handle']);
});
it('validates nip05 handle uniqueness', function () {
$pleb1 = EinundzwanzigPleb::factory()->active()->create([
'nip05_handle' => 'taken@example.com',
]);
$pleb2 = EinundzwanzigPleb::factory()->active()->create();
NostrAuth::login($pleb2->pubkey);
Livewire::test('association.profile')
->set('nip05Handle', 'taken@example.com')
->call('saveNip05Handle')
->assertHasErrors(['nip05Handle']);
});
it('can save null nip05 handle', function () {
$pleb = EinundzwanzigPleb::factory()->active()->create([
'nip05_handle' => 'old@example.com',
]);
NostrAuth::login($pleb->pubkey);
Livewire::test('association.profile')
->set('nip05Handle', null)
->call('saveNip05Handle')
->assertHasNoErrors();
expect($pleb->fresh()->nip05_handle)->toBeNull();
});
it('can update no email preference', function () { it('can update no email preference', function () {
$pleb = EinundzwanzigPleb::factory()->create(); $pleb = EinundzwanzigPleb::factory()->create();