currentLangCountry = session('lang_country'); // Nur beim ersten Mount initialisieren if ($this->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/img/domains/'.session('lang_country', 'de-DE').'.jpg', .3) ->errorCorrection('H') ->generate($this->lnurl)); } } #[On('nostrLoggedIn')] public function loginListener($pubkey): void { $user = \App\Models\User::query()->where('nostr', $pubkey)->first(); if (!$user) { $fakeName = str()->random(10); // create User $user = User::create([ 'public_key' => null, 'is_lecturer' => true, 'name' => $fakeName, 'email' => str($pubkey)->substr(-12).'@portal.einundzwanzig.space', 'nostr' => $pubkey, 'lnbits' => [ 'read_key' => null, 'url' => null, 'wallet_id' => null, ], ]); } FetchNostrProfileJob::dispatch($user); Auth::loginUsingId($user->id); Session::regenerate(); $this->redirectIntended( default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()], absolute: false), navigate: true, ); 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(); session([ 'lang_country' => $this->currentLangCountry, ]); $this->redirectIntended( default: route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()], 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); Session::regenerate(); session([ 'lang_country' => $this->currentLangCountry, ]); return to_route('dashboard', ['country' => str(session('lang_country', config('app.domain_country')))->after('-')->lower()]); } return true; } }; ?>