diff --git a/app/Http/Livewire/Auth/LNUrlAuth.php b/app/Http/Livewire/Auth/LNUrlAuth.php index da749005..bcc493b4 100644 --- a/app/Http/Livewire/Auth/LNUrlAuth.php +++ b/app/Http/Livewire/Auth/LNUrlAuth.php @@ -58,7 +58,6 @@ class LNUrlAuth extends Component \App\Models\User::find(1) ->notify(new ModelCreatedNotification($user, 'users')); - auth()->login($user); return to_route('welcome'); diff --git a/app/Http/Livewire/Wallet/LightningWallet.php b/app/Http/Livewire/Wallet/LightningWallet.php new file mode 100644 index 00000000..f501f7e8 --- /dev/null +++ b/app/Http/Livewire/Wallet/LightningWallet.php @@ -0,0 +1,71 @@ + 'required', + 'url' => 'required', + 'lnurl' => 'required', + 'qrCode' => 'required', + ]; + } + + public function mount() + { + $this->k1 = bin2hex(str()->random(32)); + if (app()->environment('local')) { + $this->url = 'https://einundzwanzig.eu-1.sharedwithexpose.com/api/lnurl-auth-callback?tag=login&k1='.$this->k1.'&action=login'; + } else { + $this->url = url('/api/lnurl-auth-callback?tag=login&k1='.$this->k1.'&action=login'); + } + $this->lnurl = lnurl\encodeUrl($this->url); + $this->qrCode = base64_encode(QrCode::format('png') + ->size(300) + ->merge('/public/android-chrome-192x192.png', .3) + ->errorCorrection('H') + ->generate($this->lnurl)); + } + + public function confirm() + { + $user = auth()->user(); + $user->change = $this->k1; + $user->change_time = now(); + $user->save(); + $this->confirmed = true; + } + + public function checkAuth() + { + $loginKey = LoginKey::query() + ->where('k1', $this->k1) + ->whereDate('created_at', '>=', now()->subMinutes(5)) + ->first(); + // you should also restrict this 👆🏻 by time, and find only the $k1 that were created in the last 5 minutes + + if ($loginKey) { + return to_route('welcome'); + } + } + + public function render() + { + return view('livewire.wallet.lightning-wallet'); + } +} diff --git a/database/migrations/2023_02_25_180846_add_change_field_to_users_table.php b/database/migrations/2023_02_25_180846_add_change_field_to_users_table.php new file mode 100644 index 00000000..7e07250c --- /dev/null +++ b/database/migrations/2023_02_25_180846_add_change_field_to_users_table.php @@ -0,0 +1,28 @@ +string('change') + ->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + // + }); + } +}; diff --git a/database/migrations/2023_02_25_181435_add_change_time_field_to_users_table.php b/database/migrations/2023_02_25_181435_add_change_time_field_to_users_table.php new file mode 100644 index 00000000..e310cf3a --- /dev/null +++ b/database/migrations/2023_02_25_181435_add_change_time_field_to_users_table.php @@ -0,0 +1,28 @@ +dateTime('change_time') + ->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/lang/de.json b/resources/lang/de.json index a894eaa2..b4a4dec6 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -570,7 +570,7 @@ "Laravel Nova": "", "Laravel Nova :version": "", "Are you sure you want to ' + mode + ' the selected resources?": "", - ":name\\'s Avatar": "", + ":name's Avatar": "", "ID": "", "Action Name": "", "Action Initiated By": "", @@ -652,7 +652,7 @@ "choice": "Auswahl", "By id": "nach ID", "Twitter": "", - "New City": "Neue Stadt / Gegend", + "New City": "Neue Stadt \/ Gegend", "My meetups": "Meine Meetups", "please limit your search here": "bitte begrenze deine Suche hier", "Deselect": "Abwählen", @@ -766,7 +766,19 @@ "Article already tweeted": "Artikel bereits getwittert", "Is this a news article?": "Dieser Artikel ist ein News-Artikel", "Are your sure?": "Bist du dir sicher?", - "Nostr public key": "", + "Nostr public key": "Nostr öffentlicher Schlüssel", "Amount": "Anzahl", - "City\/Area": "Stadt\/Gegend" + "City\/Area": "Stadt\/Gegend", + "Published on Nostr": "Veröffentlicht auf Nostr", + "Public Key": "Public Key", + "Bitcoin Event": "", + "Create venue": "Erstelle Veranstaltungsort", + "starts with npub...": "startet mit npub...", + "Are you sure you want to publish this article on Nostr?": "Bitte bestätige, dass du diesen Artikel auf Nostr veröffentlichen möchtest.", + "Publish on Nostr": "Veröffentliche auf Nostr", + "nostr": "", + "Caution": "Vorsicht", + "You overwrite your user's public key and then have to log in with the wallet, which you now use to scan or log in.": "Du überschreibst deinen öffentlichen Schlüssel und musst dich dann mit der Wallet, die du jetzt zum Scannen oder Einloggen verwendest, anmelden.", + "You are logged in as:": "Du bist angemeldet als:", + "Change lightning wallet\/pubkey": "Wechsel Lightning Wallet\/Public Key" } diff --git a/resources/lang/en.json b/resources/lang/en.json index 37e86190..bbbe1af5 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -765,5 +765,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/es.json b/resources/lang/es.json index 9788d5ad..a2f57dc9 100644 --- a/resources/lang/es.json +++ b/resources/lang/es.json @@ -765,5 +765,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/fr.json b/resources/lang/fr.json index ed8c77a6..9cb598b3 100644 --- a/resources/lang/fr.json +++ b/resources/lang/fr.json @@ -766,5 +766,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/hr.json b/resources/lang/hr.json index 24a51638..5621dfff 100644 --- a/resources/lang/hr.json +++ b/resources/lang/hr.json @@ -766,5 +766,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/it.json b/resources/lang/it.json index a7d80ca1..74643c40 100644 --- a/resources/lang/it.json +++ b/resources/lang/it.json @@ -766,5 +766,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/mk.json b/resources/lang/mk.json index e696fe49..6a330c44 100644 --- a/resources/lang/mk.json +++ b/resources/lang/mk.json @@ -766,5 +766,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/pl.json b/resources/lang/pl.json index bd1810c5..57534d78 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -766,5 +766,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/pt.json b/resources/lang/pt.json index ce5f8ed0..ebe53b19 100644 --- a/resources/lang/pt.json +++ b/resources/lang/pt.json @@ -766,5 +766,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/sv.json b/resources/lang/sv.json index 61b99120..85a09f19 100644 --- a/resources/lang/sv.json +++ b/resources/lang/sv.json @@ -728,5 +728,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/lang/tr.json b/resources/lang/tr.json index 15de22ab..852ff07b 100644 --- a/resources/lang/tr.json +++ b/resources/lang/tr.json @@ -740,5 +740,17 @@ "Are your sure?": "", "Nostr public key": "", "Amount": "", - "City\/Area": "" + "City\/Area": "", + "Published on Nostr": "", + "Public Key": "", + "Bitcoin Event": "", + "Create venue": "", + "starts with npub...": "", + "Are you sure you want to publish this article on Nostr?": "", + "Publish on Nostr": "", + "nostr": "", + "Caution": "", + "You overwrite your user\\'s public key and then have to log in with the wallet, which you now use to scan or log in.": "", + "You are logged in as:": "", + "Change lightning wallet\/pubkey": "" } \ No newline at end of file diff --git a/resources/views/livewire/wallet/lightning-wallet.blade.php b/resources/views/livewire/wallet/lightning-wallet.blade.php new file mode 100644 index 00000000..ef51ecb3 --- /dev/null +++ b/resources/views/livewire/wallet/lightning-wallet.blade.php @@ -0,0 +1,100 @@ + + + + + +
+ +
+ +
+ Now log in with a new wallet ⚡ +
+ +
+
+
+ +
+
+

{{ __('Caution') }}

+
+
    +
  • {{ __('You overwrite your user\'s public key and then have to log in with the wallet, which you now use to scan or log in.') }}
  • +
  • {{ __('You are logged in as:') }} {{ auth()->user()->name }}
  • +
+
+
+
+
+ + @if(!$confirmed) +
+ + + {{ __('Confirm') }} + +
+ @endif + + @if($confirmed) +
+ + qrcode + +
+
+ +
+
+
+ + + {{ __('Copy') }} + +
+
+ + {{ __('Click to connect') }} + + + + + +
+
+ +
+ {{ __('Scan this code or copy & paste it to your lightning wallet. Or click to login with your wallet.') }} +
+ @endif +
+ +
+ +
+
diff --git a/resources/views/navigation-menu.blade.php b/resources/views/navigation-menu.blade.php index f01b6b5b..2b8b6f5c 100644 --- a/resources/views/navigation-menu.blade.php +++ b/resources/views/navigation-menu.blade.php @@ -35,6 +35,14 @@ {{ __('My profile') }} + +
+ + + {{ __('Change lightning wallet/pubkey') }} + +
diff --git a/routes/api.php b/routes/api.php index 68b35445..577734f7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -95,21 +95,32 @@ Route::middleware([]) Route::get('/lnurl-auth-callback', function (Request $request) { if (lnurl\auth($request->k1, $request->sig, $request->key)) { // find User by $wallet_public_key - $user = User::query() - ->whereBlind('public_key', 'public_key_index', $request->key) - ->first(); + if ($user = User::query() + ->where('change', $request->k1) + ->where('change_time', '>', now()->subMinutes(5)) + ->first()) { + $user->public_key = $request->key; + $user->change = null; + $user->change_time = null; + $user->save(); + } else { + $user = User::query() + ->whereBlind('public_key', 'public_key_index', $request->key) + ->first(); + } if (!$user) { + $fakeName = str()->random(10); // create User $user = User::create([ 'public_key' => $request->key, 'is_lecturer' => true, - 'name' => $request->key, + 'name' => $fakeName, 'email' => str($request->key)->substr(-12).'@portal.einundzwanzig.space', ]); $user->ownedTeams() ->save(Team::forceCreate([ 'user_id' => $user->id, - 'name' => $request->key."'s Team", + 'name' => $fakeName."'s Team", 'personal_team' => true, ])); } diff --git a/routes/web.php b/routes/web.php index ef7e568a..72a9921b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -103,10 +103,18 @@ Route::middleware([]) ->get('/lecturer-material/{libraryItem:slug}', \App\Http\Livewire\News\InternArticleView::class) ->name('lecturerMaterial.view'); -Route::middleware([]) +Route::middleware([ + 'auth', +]) ->get('/my-meetups', \App\Http\Livewire\Profile\Meetups::class) ->name('profile.meetups'); +Route::middleware([ + 'auth', +]) + ->get('/my-lightning-wallet', \App\Http\Livewire\Wallet\LightningWallet::class) + ->name('profile.wallet'); + Route::get('/auth/ln', \App\Http\Livewire\Auth\LNUrlAuth::class) ->name('auth.ln');