-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45b1b66
commit ddb79ae
Showing
18 changed files
with
3,772 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Auth; | ||
|
||
use App\Models\Team; | ||
use App\Models\User; | ||
use Livewire\Component; | ||
|
||
class Login extends Component | ||
{ | ||
public array $userProfile = []; | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
'userProfile.npub' => 'required|string', | ||
'userProfile.pubkey' => 'required|string', | ||
|
||
'userProfile.banner' => 'required|string', | ||
'userProfile.image' => 'required|string', | ||
|
||
'userProfile.name' => 'required|string', | ||
'userProfile.username' => 'required|string', | ||
'userProfile.website' => 'required|string', | ||
'userProfile.about' => 'required|string', | ||
'userProfile.displayName' => 'required|string', | ||
'userProfile.lud16' => 'required|string', | ||
'userProfile.nip05' => 'required|string', | ||
]; | ||
} | ||
|
||
public function updatedUserProfile($value) | ||
{ | ||
if ($value['npub']) { | ||
$firstUser = User::query()->where('nostr', $value['npub'])->first(); | ||
if ($firstUser) { | ||
auth()->login($firstUser, true); | ||
|
||
return to_route('welcome'); | ||
} else { | ||
$fakeName = str()->random(10); | ||
// create User | ||
$user = User::create([ | ||
'is_lecturer' => true, | ||
'name' => $fakeName, | ||
'email' => str($fakeName)->slug() . '@portal.einundzwanzig.space', | ||
'email_verified_at' => now(), | ||
'lnbits' => [ | ||
'read_key' => null, | ||
'url' => null, | ||
'wallet_id' => null, | ||
], | ||
'nostr' => $value['npub'], | ||
]); | ||
$user->ownedTeams() | ||
->save(Team::forceCreate([ | ||
'user_id' => $user->id, | ||
'name' => $fakeName . "'s Team", | ||
'personal_team' => true, | ||
])); | ||
auth()->login($user, true); | ||
|
||
return to_route('welcome'); | ||
} | ||
} | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.login')->layout('layouts.guest'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Auth; | ||
|
||
use App\Models\User; | ||
use Livewire\Component; | ||
|
||
class LoginWithNDK extends Component | ||
{ | ||
public $existingAccount = false; | ||
|
||
public array $userProfile = []; | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
'userProfile.npub' => 'required|string', | ||
'userProfile.pubkey' => 'required|string', | ||
|
||
'userProfile.banner' => 'required|string', | ||
'userProfile.image' => 'required|string', | ||
|
||
'userProfile.name' => 'required|string', | ||
'userProfile.username' => 'required|string', | ||
'userProfile.website' => 'required|string', | ||
'userProfile.about' => 'required|string', | ||
'userProfile.displayName' => 'required|string', | ||
'userProfile.lud16' => 'required|string', | ||
'userProfile.nip05' => 'required|string', | ||
]; | ||
} | ||
|
||
public function updatedUserProfile($value) | ||
{ | ||
if (User::query()->where('nostr', $value['npub'])->exists()) { | ||
$this->existingAccount = true; | ||
} | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.auth.login-with-n-d-k')->layout('layouts.guest'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<x-jet-authentication-card> | ||
|
||
<x-slot name="logo"> | ||
<x-jet-authentication-card-logo/> | ||
</x-slot> | ||
|
||
<div> | ||
<div | ||
wire:ignore | ||
x-data="{ | ||
userProfile: @entangle('userProfile'), | ||
init() { | ||
const nip07signer = new window.NDKNip07Signer(); | ||
const ndk = new window.NDK({ | ||
explicitRelayUrls: ['wss://nostr.codingarena.de'], | ||
signer: nip07signer | ||
}); | ||
ndk.connect(); | ||
}, | ||
login() { | ||
nip07signer.user().then(async (user) => { | ||
if (!!user.npub) { | ||
console.log('user pub: ' + user.npub); | ||
const ndkUser = ndk.getUser({ | ||
npub: user.npub, | ||
}); | ||
await ndkUser.fetchProfile(); | ||
console.log(ndkUser); | ||
this.userProfile = ndkUser.profile; | ||
} | ||
}); | ||
} | ||
}" | ||
> | ||
|
||
<div class="space-y-6" x-init="init()"> | ||
<x-button x-show="!userProfile.npub" primary label="NIP-07 Login" icon="login" @click="login()"/> | ||
<p x-text="userProfile.npub"></p> | ||
<p x-text="userProfile.about"></p> | ||
<img :src="userProfile.image" alt="image"/> | ||
</div> | ||
</div> | ||
|
||
@if($existingAccount) | ||
<div class="mt-12 text-red-500 space-y-6"> | ||
<p>Es existiert ein Account mit dem npub {{ $userProfile['npub'] }}</p> | ||
</div> | ||
@endif | ||
</div> | ||
|
||
</x-jet-authentication-card> |
Oops, something went wrong.