k1 === null) { $this->k1 = bin2hex(str()->random(32)); if (app()->environment('local')) { $this->url = 'https://mmy4dp8eab.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)); } } #[On('nostrLoggedIn')] public function loginListener($pubkey): void { $user = \App\Models\User::query()->where('nostr', $pubkey)->first(); if ($user) { Auth::loginUsingId($user->id); Session::regenerate(); $this->redirectIntended( default: route('dashboard', ['country' => 'de'], absolute: false), navigate: true, ); return; } return; $this->validate(); $this->ensureIsNotRateLimited(); if (!Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) { RateLimiter::hit($this->throttleKey()); throw ValidationException::withMessages([ 'email' => __('auth.failed'), ]); } RateLimiter::clear($this->throttleKey()); Session::regenerate(); $this->redirectIntended( default: route('dashboard', ['country' => 'de'], absolute: false), navigate: true ); } /** * Ensure the authentication request is not rate limited. */ protected function ensureIsNotRateLimited(): void { if (!RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { return; } event(new Lockout(request())); $seconds = RateLimiter::availableIn($this->throttleKey()); throw ValidationException::withMessages([ 'email' => __('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), ]); } /** * Get the authentication rate limiting throttle key. */ protected function throttleKey(): string { return Str::transliterate(Str::lower($this->email).'|'.request()->ip()); } public function checkAuth() { $loginKey = LoginKey::query() ->where('k1', $this->k1) ->whereDate('created_at', '>=', now()->subMinutes(5)) ->first(); if ($loginKey) { $user = User::find($loginKey->user_id); \App\Models\User::find(1) ->notify(new ModelCreatedNotification($user, 'users')); auth()->login($user); return to_route('dashboard', ['country' => 'de']); } return true; } }; ?>