diff --git a/app/Auth/NostrSessionGuard.php b/app/Auth/NostrSessionGuard.php
new file mode 100644
index 0000000..0d2fc13
--- /dev/null
+++ b/app/Auth/NostrSessionGuard.php
@@ -0,0 +1,41 @@
+updateSession($user->getAuthIdentifier());
+
+ $this->setUser($user);
+
+ $this->fireLoginEvent($user, false);
+ }
+
+ protected function updateSession($id): void
+ {
+ $this->session->put($this->getName(), $id);
+ $this->session->migrate(true);
+ }
+
+ public function user(): ?Authenticatable
+ {
+ if ($this->user !== null) {
+ return $this->user;
+ }
+
+ $id = $this->session->get($this->getName());
+
+ if ($id !== null) {
+ $this->user = $this->provider->retrieveById($id);
+ }
+
+ return $this->user;
+ }
+}
diff --git a/app/Auth/NostrUser.php b/app/Auth/NostrUser.php
new file mode 100644
index 0000000..79a61da
--- /dev/null
+++ b/app/Auth/NostrUser.php
@@ -0,0 +1,64 @@
+pubkey = $pubkey;
+ $this->pleb = \App\Models\EinundzwanzigPleb::query()
+ ->where('pubkey', $pubkey)
+ ->first();
+ }
+
+ public function getAuthIdentifierName(): string
+ {
+ return 'pubkey';
+ }
+
+ public function getAuthIdentifier(): string
+ {
+ return $this->pubkey;
+ }
+
+ public function getAuthPassword(): string
+ {
+ return '';
+ }
+
+ public function getRememberToken(): ?string
+ {
+ return null;
+ }
+
+ public function setRememberToken($value): void
+ {
+ //
+ }
+
+ public function getRememberTokenName(): ?string
+ {
+ return null;
+ }
+
+ public function getAuthPasswordName(): string
+ {
+ return 'password';
+ }
+
+ public function getPubkey(): string
+ {
+ return $this->pubkey;
+ }
+
+ public function getPleb(): ?object
+ {
+ return $this->pleb;
+ }
+}
diff --git a/app/Auth/NostrUserProvider.php b/app/Auth/NostrUserProvider.php
new file mode 100644
index 0000000..3802804
--- /dev/null
+++ b/app/Auth/NostrUserProvider.php
@@ -0,0 +1,43 @@
+getPubkey() === ($credentials['pubkey'] ?? null);
+ }
+
+ public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
+ {
+ //
+ }
+}
diff --git a/app/Livewire/Traits/WithNostrAuth.php b/app/Livewire/Traits/WithNostrAuth.php
new file mode 100644
index 0000000..cbb35af
--- /dev/null
+++ b/app/Livewire/Traits/WithNostrAuth.php
@@ -0,0 +1,55 @@
+currentPubkey = $pubkey;
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()
+ ->where('pubkey', $pubkey)
+ ->first();
+
+ if ($this->currentPleb && in_array($this->currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
+ $this->canEdit = true;
+ }
+
+ $this->isAllowed = true;
+ }
+
+ #[On('nostrLoggedOut')]
+ public function handleNostrLogout(): void
+ {
+ NostrAuth::logout();
+
+ $this->isAllowed = false;
+ $this->currentPubkey = null;
+ $this->currentPleb = null;
+ $this->canEdit = false;
+ }
+
+ public function mountNostrAuth(): void
+ {
+ if ($user = NostrAuth::user()) {
+ $this->currentPubkey = $user->getPubkey();
+ $this->currentPleb = $user->getPleb();
+ $this->isAllowed = true;
+
+ if ($this->currentPleb && in_array($this->currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
+ $this->canEdit = true;
+ }
+ }
+ }
+}
diff --git a/app/Providers/NostrAuthServiceProvider.php b/app/Providers/NostrAuthServiceProvider.php
new file mode 100644
index 0000000..33256a4
--- /dev/null
+++ b/app/Providers/NostrAuthServiceProvider.php
@@ -0,0 +1,30 @@
+loginByPubkey($pubkey);
+ Session::regenerate();
+ }
+
+ /**
+ * Logout the current Nostr user
+ */
+ public static function logout(): void
+ {
+ if (Auth::guard('nostr')->check()) {
+ Session::flush();
+ }
+ }
+
+ /**
+ * Get the currently authenticated Nostr user
+ */
+ public static function user(): ?NostrUser
+ {
+ return Auth::guard('nostr')->user();
+ }
+
+ /**
+ * Check if a Nostr user is authenticated
+ */
+ public static function check(): bool
+ {
+ return Auth::guard('nostr')->check();
+ }
+
+ /**
+ * Get the current pubkey (convenience method)
+ */
+ public static function pubkey(): ?string
+ {
+ return self::user()?->getPubkey();
+ }
+
+ /**
+ * Get the current pleb (convenience method)
+ */
+ public static function pleb(): ?object
+ {
+ return self::user()?->getPleb();
+ }
+}
diff --git a/bootstrap/providers.php b/bootstrap/providers.php
index 90915e8..8e4d42c 100644
--- a/bootstrap/providers.php
+++ b/bootstrap/providers.php
@@ -3,5 +3,6 @@
return [
App\Providers\AppServiceProvider::class,
App\Providers\FolioServiceProvider::class,
+ App\Providers\NostrAuthServiceProvider::class,
App\Providers\VoltServiceProvider::class,
];
diff --git a/config/auth.php b/config/auth.php
index 0ba5d5d..c8aee63 100644
--- a/config/auth.php
+++ b/config/auth.php
@@ -40,6 +40,10 @@ return [
'driver' => 'session',
'provider' => 'users',
],
+ 'nostr' => [
+ 'driver' => 'nostr-session',
+ 'provider' => 'nostr',
+ ],
],
/*
@@ -64,6 +68,9 @@ return [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\User::class),
],
+ 'nostr' => [
+ 'driver' => 'nostr',
+ ],
// 'users' => [
// 'driver' => 'database',
diff --git a/resources/views/components/layouts/app.blade.php b/resources/views/components/layouts/app.blade.php
index 831170c..f884b3d 100644
--- a/resources/views/components/layouts/app.blade.php
+++ b/resources/views/components/layouts/app.blade.php
@@ -69,8 +69,16 @@
{{--@include('components.layouts.partials.notification-buttons')--}}
-
+ @if(\App\Support\NostrAuth::check())
+
+ @else
+
+ @endif
diff --git a/resources/views/components/layouts/navigation/admin.blade.php b/resources/views/components/layouts/navigation/admin.blade.php
index 176e5e9..4dc4fed 100644
--- a/resources/views/components/layouts/navigation/admin.blade.php
+++ b/resources/views/components/layouts/navigation/admin.blade.php
@@ -6,7 +6,7 @@
Admin-Bereich
- -
+ {{--
-
@@ -15,7 +15,7 @@
class="text-sm font-medium ml-4 lg:opacity-0 lg:sidebar-expanded:opacity-100 2xl:opacity-100 duration-200">Einstellungen
-
+ --}}
-
diff --git a/resources/views/pages/association/election/index.blade.php b/resources/views/pages/association/election/index.blade.php
index 888cdc3..284f4c4 100644
--- a/resources/views/pages/association/election/index.blade.php
+++ b/resources/views/pages/association/election/index.blade.php
@@ -21,6 +21,16 @@ mount(function () {
$this->elections = \App\Models\Election::query()
->get()
->toArray();
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $logPubkeys = [
+ '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033',
+ '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279',
+ ];
+ if (in_array($this->currentPubkey, $logPubkeys, true)) {
+ $this->isAllowed = true;
+ }
+ }
});
on([
diff --git a/resources/views/pages/association/members/admin.blade.php b/resources/views/pages/association/members/admin.blade.php
index 229a7c5..0c6a289 100644
--- a/resources/views/pages/association/members/admin.blade.php
+++ b/resources/views/pages/association/members/admin.blade.php
@@ -21,6 +21,24 @@ state(['isAllowed' => false]);
state(['currentPubkey' => null]);
state(['members' => []]);
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()
+ ->where('pubkey', $this->currentPubkey )->first();
+ $allowedPubkeys = [
+ '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033',
+ '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279',
+ '7acf30cf60b85c62b8f654556cc21e4016df8f5604b3b6892794f88bb80d7a1d',
+ 'f240be2b684f85cc81566f2081386af81d7427ea86250c8bde6b7a8500c761ba',
+ '19e358b8011f5f4fc653c565c6d4c2f33f32661f4f90982c9eedc292a8774ec3',
+ ];
+ if (in_array($this->currentPubkey, $allowedPubkeys, true)) {
+ $this->isAllowed = true;
+ }
+ }
+});
+
on([
'nostrLoggedOut' => function () {
$this->isAllowed = false;
diff --git a/resources/views/pages/association/news/index.blade.php b/resources/views/pages/association/news/index.blade.php
index 1692ade..5d7474d 100644
--- a/resources/views/pages/association/news/index.blade.php
+++ b/resources/views/pages/association/news/index.blade.php
@@ -31,6 +31,17 @@ state([
'currentPleb' => null,
]);
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $this->currentPubkey)->first();
+ if (in_array($this->currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
+ $this->canEdit = true;
+ }
+ $this->isAllowed = true;
+ }
+});
+
on([
'nostrLoggedIn' => function ($pubkey) {
$this->currentPubkey = $pubkey;
diff --git a/resources/views/pages/association/profile.blade.php b/resources/views/pages/association/profile.blade.php
index c4e4bf3..f7340ae 100644
--- a/resources/views/pages/association/profile.blade.php
+++ b/resources/views/pages/association/profile.blade.php
@@ -35,8 +35,34 @@ state([
form(\App\Livewire\Forms\ApplicationForm::class);
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()
+ ->with([
+ 'paymentEvents' => fn($query)
+ => $query->where('year', date('Y')),
+ ])
+ ->where('pubkey', $this->currentPubkey)->first();
+ $this->email = $this->currentPleb->email;
+ $this->no = $this->currentPleb->no_email;
+ $this->showEmail = !$this->no;
+ if ($this->currentPleb->association_status === \App\Enums\AssociationStatus::ACTIVE) {
+ $this->amountToPay = config('app.env') === 'production' ? 21000 : 1;
+ }
+ if ($this->currentPleb->paymentEvents->count() < 1) {
+ $this->createPaymentEvent();
+ $this->currentPleb->load('paymentEvents');
+ }
+ $this->loadEvents();
+ $this->listenForPayment();
+ }
+});
+
on([
'nostrLoggedIn' => function ($pubkey) {
+ \App\Support\NostrAuth::login($pubkey);
+
$this->currentPubkey = $pubkey;
$this->currentPleb = \App\Models\EinundzwanzigPleb::query()
->with([
@@ -58,6 +84,8 @@ on([
$this->listenForPayment();
},
'nostrLoggedOut' => function () {
+ \App\Support\NostrAuth::logout();
+
$this->currentPubkey = null;
$this->currentPleb = null;
$this->yearsPaid = [];
@@ -422,8 +450,6 @@ $loadEvents = function () {
-
{{-- https://v.nostr.build/bomfuwLnOTIDrP4y.mp4 --}}
diff --git a/resources/views/pages/association/project-support/[ProjectProposal:slug].blade.php b/resources/views/pages/association/project-support/[ProjectProposal:slug].blade.php
index 431353a..7957091 100644
--- a/resources/views/pages/association/project-support/[ProjectProposal:slug].blade.php
+++ b/resources/views/pages/association/project-support/[ProjectProposal:slug].blade.php
@@ -28,6 +28,13 @@ state([
'otherVotes' => fn() => $this->getOtherVotes(),
]);
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->handleNostrLoggedIn($this->currentPubkey);
+ }
+});
+
on([
'nostrLoggedIn' => fn($pubkey) => $this->handleNostrLoggedIn($pubkey),
'nostrLoggedOut' => fn() => $this->handleNostrLoggedOut(),
diff --git a/resources/views/pages/association/project-support/form/[ProjectProposal:slug].blade.php b/resources/views/pages/association/project-support/form/[ProjectProposal:slug].blade.php
index 47cf1e7..dbda577 100644
--- a/resources/views/pages/association/project-support/form/[ProjectProposal:slug].blade.php
+++ b/resources/views/pages/association/project-support/form/[ProjectProposal:slug].blade.php
@@ -31,6 +31,14 @@ mount(function ($projectProposal) {
usesFileUploads();
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $this->currentPubkey)->first();
+ $this->isAllowed = true;
+ }
+});
+
on([
'nostrLoggedIn' => function ($pubkey) {
$this->currentPubkey = $pubkey;
diff --git a/resources/views/pages/association/project-support/form/create.blade.php b/resources/views/pages/association/project-support/form/create.blade.php
index f129799..47f890d 100644
--- a/resources/views/pages/association/project-support/form/create.blade.php
+++ b/resources/views/pages/association/project-support/form/create.blade.php
@@ -25,6 +25,14 @@ state([
usesFileUploads();
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $this->currentPubkey)->first();
+ $this->isAllowed = true;
+ }
+});
+
on([
'nostrLoggedIn' => function ($pubkey) {
$this->currentPubkey = $pubkey;
diff --git a/resources/views/pages/association/project-support/index.blade.php b/resources/views/pages/association/project-support/index.blade.php
index 61a5250..7e7b4e2 100644
--- a/resources/views/pages/association/project-support/index.blade.php
+++ b/resources/views/pages/association/project-support/index.blade.php
@@ -55,6 +55,14 @@ $projects = computed(function () {
return $this->projects;
});
+mount(function () {
+ if (\App\Support\NostrAuth::check()) {
+ $this->currentPubkey = \App\Support\NostrAuth::pubkey();
+ $this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $this->currentPubkey)->first();
+ $this->isAllowed = true;
+ }
+});
+
on([
'nostrLoggedIn' => function ($pubkey) {
$this->currentPubkey = $pubkey;
diff --git a/routes/web.php b/routes/web.php
index 4f797c4..13eb67d 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -2,6 +2,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\Session;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
Route::redirect('/', '/association/profile');
@@ -11,3 +12,9 @@ Route::get('dl/{media}', function (Media $media, Request $request) {
})
->name('dl')
->middleware('signed');
+
+Route::post('logout', function () {
+ \App\Support\NostrAuth::logout();
+ Session::flush();
+ return redirect('/');
+})->name('logout');