mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions. You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root. For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\Auth;
|
|
|
|
use App\Models\LoginKey;
|
|
use App\Models\User;
|
|
use App\Notifications\ModelCreatedNotification;
|
|
use eza\lnurl;
|
|
use Livewire\Component;
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
|
|
|
class LNUrlAuth extends Component
|
|
{
|
|
public ?string $k1 = null;
|
|
|
|
protected ?string $url = null;
|
|
|
|
protected ?string $lnurl = null;
|
|
|
|
protected ?string $qrCode = null;
|
|
|
|
public function switchToEmailLogin()
|
|
{
|
|
return to_route('login');
|
|
}
|
|
|
|
public function switchToEmailSignup()
|
|
{
|
|
return to_route('register');
|
|
}
|
|
|
|
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 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) {
|
|
$user = User::find($loginKey->user_id);
|
|
|
|
\App\Models\User::find(1)
|
|
->notify(new ModelCreatedNotification($user, 'users'));
|
|
|
|
auth()->login($user);
|
|
|
|
return to_route('welcome');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.auth.ln-url-auth')->layout('layouts.guest');
|
|
}
|
|
}
|