change wallet/public key

This commit is contained in:
HolgerHatGarKeineNode
2023-02-25 19:28:28 +01:00
parent de8c6060c1
commit 694fd1146f
19 changed files with 406 additions and 21 deletions

View File

@@ -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');

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Http\Livewire\Wallet;
use App\Models\LoginKey;
use eza\lnurl;
use Livewire\Component;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class LightningWallet extends Component
{
public ?string $k1 = null;
public ?string $url = null;
public ?string $lnurl = null;
public ?string $qrCode = null;
public bool $confirmed = false;
public function rules()
{
return [
'k1' => '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');
}
}

View File

@@ -0,0 +1,28 @@
<?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('users', function (Blueprint $table) {
$table->string('change')
->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
//
});
}
};

View File

@@ -0,0 +1,28 @@
<?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('users', function (Blueprint $table) {
$table->dateTime('change_time')
->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
//
});
}
};

View File

@@ -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"
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -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": ""
}

View File

@@ -0,0 +1,100 @@
<x-jet-authentication-card>
<x-slot name="logo">
<x-jet-authentication-card-logo/>
</x-slot>
<div>
<div>
<div class="text-center text-2xl text-gray-800 mt-6">
Now log in with a new wallet
</div>
<div class="rounded-md bg-red-50 p-4 my-2">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z"
clip-rule="evenodd"/>
</svg>
</div>
<div class="ml-3">
<h3 class="text-sm font-medium text-red-800">{{ __('Caution') }}</h3>
<div class="mt-2 text-sm text-red-700">
<ul role="list" class="list-disc space-y-1 pl-5">
<li>{{ __('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.') }}</li>
<li>{{ __('You are logged in as:') }} {{ auth()->user()->name }}</li>
</ul>
</div>
</div>
</div>
</div>
@if(!$confirmed)
<div>
<x-button primary wire:click="confirm">
<i class="fa-thin fa-check"></i>
{{ __('Confirm') }}
</x-button>
</div>
@endif
@if($confirmed)
<div class="flex justify-center" wire:key="qrcode">
<a href="lightning:{{ $this->lnurl }}">
<img src="{{ 'data:image/png;base64, '. $this->qrCode }}" alt="qrcode">
</a>
</div>
<div class="my-2 flex justify-center font-mono break-all">
<input class="w-full" readonly wire:key="lnurl" onClick="this.select();"
value="lightning:{{ $this->lnurl }}"/>
</div>
<div class="flex justify-between w-full">
<div
x-data="{
textToCopy: 'lightning:{{ $this->lnurl }}',
}"
@click.prevent="window.navigator.clipboard.writeText(textToCopy);window.$wireui.notify({title:'{{ __('URL copied!') }}',icon:'success'});"
>
<x-button
black
>
<i class="fa fa-thin fa-clipboard"></i>
{{ __('Copy') }}
</x-button>
</div>
<div
x-data="{
textToCopy: 'lightning:{{ $this->lnurl }}',
}"
@click.prevent="window.navigator.clipboard.writeText(textToCopy);window.$wireui.notify({title:'{{ __('URL copied!') }}',icon:'success'});"
>
<x-button
primary
black
:href="'lightning:'.$this->lnurl"
>
{{ __('Click to connect') }}
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512"
height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
<path fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"
d="M461.81 53.81a4.4 4.4 0 00-3.3-3.39c-54.38-13.3-180 34.09-248.13 102.17a294.9 294.9 0 00-33.09 39.08c-21-1.9-42-.3-59.88 7.5-50.49 22.2-65.18 80.18-69.28 105.07a9 9 0 009.8 10.4l81.07-8.9a180.29 180.29 0 001.1 18.3 18.15 18.15 0 005.3 11.09l31.39 31.39a18.15 18.15 0 0011.1 5.3 179.91 179.91 0 0018.19 1.1l-8.89 81a9 9 0 0010.39 9.79c24.9-4 83-18.69 105.07-69.17 7.8-17.9 9.4-38.79 7.6-59.69a293.91 293.91 0 0039.19-33.09c68.38-68 115.47-190.86 102.37-247.95zM298.66 213.67a42.7 42.7 0 1160.38 0 42.65 42.65 0 01-60.38 0z"></path>
<path fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"
d="M109.64 352a45.06 45.06 0 00-26.35 12.84C65.67 382.52 64 448 64 448s65.52-1.67 83.15-19.31A44.73 44.73 0 00160 402.32"></path>
</svg>
</x-button>
</div>
</div>
<div class="pt-12" x-show="!currentUser">
{{ __('Scan this code or copy & paste it to your lightning wallet. Or click to login with your wallet.') }}
</div>
@endif
</div>
</div>
<div wire:poll="checkAuth" wire:key="checkAuth"></div>
</x-jet-authentication-card>

View File

@@ -35,6 +35,14 @@
{{ __('My profile') }}
</x-button>
</div>
<div>
<x-button xs amber href="{{ route('profile.wallet') }}"
:active="request()->routeIs('profile.wallet')">
<i class="fa fa-thin fa-user"></i>
{{ __('Change lightning wallet/pubkey') }}
</x-button>
</div>
</div>
</div>

View File

@@ -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,
]));
}

View File

@@ -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');