ln auth added and email service activated

This commit is contained in:
Benjamin Takats
2022-12-01 20:35:54 +01:00
parent cfa566ebbf
commit 0003dc2bc8
9 changed files with 283 additions and 29 deletions

View File

@@ -10,34 +10,37 @@ use SimpleSoftwareIO\QrCode\Facades\QrCode;
class LNUrlAuth extends Component class LNUrlAuth extends Component
{ {
protected ?string $k1 = null; public ?string $k1 = null;
protected ?string $url = null;
protected ?string $lnurl = null; protected ?string $lnurl = null;
protected ?string $qrCode = null; protected ?string $qrCode = null;
public function switchToEmail() public function switchToEmail()
{ {
dd('test'); return to_route('login');
} }
public function mount() public function mount()
{ {
$this->k1 = bin2hex(str()->random(32)); $this->k1 = bin2hex(str()->random(32));
$this->lnurl = lnurl\encodeUrl(url('/lnurl-auth-callback', $this->url = url('/lnurl-auth-callback?tag=login&k1='.$this->k1.'&action=login');
['tag' => 'login', 'k1' => $this->k1, 'action' => 'login'])); $this->lnurl = lnurl\encodeUrl($this->url);
$this->qrCode = QrCode::size(300) $this->qrCode = QrCode::size(300)
->generate($this->lnurl); ->generate($this->lnurl);
} }
public function checkAuth() public function checkAuth()
{ {
$loginKey = LoginKey::where('k1', $this->k1) $loginKey = LoginKey::query()
->where('created_at', '<=', now()->subMinutes(5)) ->where('k1', $this->k1)
->whereDate('created_at', '>=', now()->subMinutes(5))
->first(); ->first();
// you should also restrict this 👆🏻 by time, and find only the $k1 that were created in the last 5 minutes // you should also restrict this 👆🏻 by time, and find only the $k1 that were created in the last 5 minutes
if ($loginKey) { if ($loginKey) {
$user = User::find($loginKey->user_id); $user = User::find($loginKey->user_id);
auth()->login($user); auth()->login($user);
return to_route('welcome'); return to_route('welcome');
} }

View File

@@ -22,16 +22,7 @@ class User extends Authenticatable implements MustVerifyEmail
use TwoFactorAuthenticatable; use TwoFactorAuthenticatable;
use HasRoles; use HasRoles;
/** protected $guarded = [];
* The attributes that are mass assignable.
* @var string[]
*/
protected $fillable = [
'name',
'email',
'password',
'is_lecturer',
];
/** /**
* The attributes that should be hidden for serialization. * The attributes that should be hidden for serialization.

View File

@@ -24,6 +24,8 @@
"spatie/laravel-google-fonts": "^1.2", "spatie/laravel-google-fonts": "^1.2",
"spatie/laravel-sluggable": "^3.4", "spatie/laravel-sluggable": "^3.4",
"stijnvanouplines/blade-country-flags": "^1.0", "stijnvanouplines/blade-country-flags": "^1.0",
"symfony/http-client": "^6.2",
"symfony/mailgun-mailer": "^6.2",
"wireui/wireui": "^1.17", "wireui/wireui": "^1.17",
"ziffmedia/nova-select-plus": "^2.0" "ziffmedia/nova-select-plus": "^2.0"
}, },

233
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "fc79bdd86821000c070c614e0385746c", "content-hash": "d1978838425670301ad666b43b7517ec",
"packages": [ "packages": [
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@@ -5768,6 +5768,172 @@
], ],
"time": "2022-10-09T08:55:40+00:00" "time": "2022-10-09T08:55:40+00:00"
}, },
{
"name": "symfony/http-client",
"version": "v6.2.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-client.git",
"reference": "153540b6ed72eecdcb42dc847f8d8cf2e2516e8e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-client/zipball/153540b6ed72eecdcb42dc847f8d8cf2e2516e8e",
"reference": "153540b6ed72eecdcb42dc847f8d8cf2e2516e8e",
"shasum": ""
},
"require": {
"php": ">=8.1",
"psr/log": "^1|^2|^3",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/http-client-contracts": "^3",
"symfony/service-contracts": "^1.0|^2|^3"
},
"provide": {
"php-http/async-client-implementation": "*",
"php-http/client-implementation": "*",
"psr/http-client-implementation": "1.0",
"symfony/http-client-implementation": "3.0"
},
"require-dev": {
"amphp/amp": "^2.5",
"amphp/http-client": "^4.2.1",
"amphp/http-tunnel": "^1.0",
"amphp/socket": "^1.1",
"guzzlehttp/promises": "^1.4",
"nyholm/psr7": "^1.0",
"php-http/httplug": "^1.0|^2.0",
"psr/http-client": "^1.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/process": "^5.4|^6.0",
"symfony/stopwatch": "^5.4|^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\HttpClient\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/http-client/tree/v6.2.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-14T10:13:36+00:00"
},
{
"name": "symfony/http-client-contracts",
"version": "v3.1.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-client-contracts.git",
"reference": "fd038f08c623ab5d22b26e9ba35afe8c79071800"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/fd038f08c623ab5d22b26e9ba35afe8c79071800",
"reference": "fd038f08c623ab5d22b26e9ba35afe8c79071800",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"suggest": {
"symfony/http-client-implementation": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.1-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"psr-4": {
"Symfony\\Contracts\\HttpClient\\": ""
},
"exclude-from-classmap": [
"/Test/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Generic abstractions related to HTTP clients",
"homepage": "https://symfony.com",
"keywords": [
"abstractions",
"contracts",
"decoupling",
"interfaces",
"interoperability",
"standards"
],
"support": {
"source": "https://github.com/symfony/http-client-contracts/tree/v3.1.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-04-22T07:30:54+00:00"
},
{ {
"name": "symfony/http-foundation", "name": "symfony/http-foundation",
"version": "v6.2.0", "version": "v6.2.0",
@@ -6035,6 +6201,71 @@
], ],
"time": "2022-11-28T17:18:31+00:00" "time": "2022-11-28T17:18:31+00:00"
}, },
{
"name": "symfony/mailgun-mailer",
"version": "v6.2.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/mailgun-mailer.git",
"reference": "c5364fbcf5581ba9eae569db12b380b9255ce238"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mailgun-mailer/zipball/c5364fbcf5581ba9eae569db12b380b9255ce238",
"reference": "c5364fbcf5581ba9eae569db12b380b9255ce238",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/mailer": "^5.4|^6.0"
},
"require-dev": {
"symfony/http-client": "^5.4|^6.0"
},
"type": "symfony-mailer-bridge",
"autoload": {
"psr-4": {
"Symfony\\Component\\Mailer\\Bridge\\Mailgun\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Mailgun Mailer Bridge",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/mailgun-mailer/tree/v6.2.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-10-09T08:55:40+00:00"
},
{ {
"name": "symfony/mime", "name": "symfony/mime",
"version": "v6.2.0", "version": "v6.2.0",

View File

@@ -50,6 +50,10 @@
</x-jet-button> </x-jet-button>
</div> </div>
<div class="flex items-center justify-left mt-4">
<x-button href="{{ route('auth.ln') }}" primary icon="lightning-bolt">LN-Auth</x-button>
</div>
</form> </form>
</x-jet-authentication-card> </x-jet-authentication-card>
</x-guest-layout> </x-guest-layout>

View File

@@ -66,10 +66,13 @@
<a class="underline text-sm text-gray-600 hover:text-gray-900" href="{{ route('login') }}"> <a class="underline text-sm text-gray-600 hover:text-gray-900" href="{{ route('login') }}">
{{ __('Already registered?') }} {{ __('Already registered?') }}
</a> </a>
Wurde noch nicht implementiert <x-jet-button class="ml-4">
{{--<x-jet-button class="ml-4">
{{ __('Register') }} {{ __('Register') }}
</x-jet-button>--}} </x-jet-button>
</div>
<div class="flex items-center justify-left mt-4">
<x-button href="{{ route('auth.ln') }}" primary icon="lightning-bolt">LN-Auth</x-button>
</div> </div>
</form> </form>
</x-jet-authentication-card> </x-jet-authentication-card>

View File

@@ -15,9 +15,13 @@
<div class="flex items-center justify-end mt-4"> <div class="flex items-center justify-end mt-4">
<x-jet-button class="ml-4" wire:click="switchToEmail"> <x-button icon="login" secondary class="ml-4" wire:click="switchToEmail">
{{ __('Switch to E-Mail login') }} {{ __('Switch to E-Mail login') }}
</x-jet-button> </x-button>
<x-button icon="at-symbol" primary class="ml-4" wire:click="switchToEmail">
{{ __('Switch to E-Mail signup') }}
</x-button>
</div> </div>
</div> </div>

View File

@@ -1,10 +1,11 @@
<?php <?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Models\LoginKey; use App\Models\LoginKey;
use App\Models\Team;
use App\Models\User; use App\Models\User;
use eza\lnurl; use eza\lnurl;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@@ -17,21 +18,29 @@ use eza\lnurl;
| |
*/ */
Route::middleware('auth:sanctum')->get('/user', function (Request $request) { Route::middleware('auth:sanctum')
->get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::get('/lnurl-auth-callback', function (\Illuminate\Http\Request $request) { Route::get('/lnurl-auth-callback', function (\Illuminate\Http\Request $request) {
if (lnurl\auth($request->k1, $request->signature, $request->wallet_public_key)) { if (lnurl\auth($request->k1, $request->sig, $request->key)) {
// find User by $wallet_public_key // find User by $wallet_public_key
$user = User::where('public_key', $request->key) $user = User::where('public_key', $request->key)
->first(); ->first();
if (!$user) { if (!$user) {
// create User // create User
$user = User::create([ $user = User::create([
'public_key' => $request->wallet_public_key, 'public_key' => $request->key,
'is_lecturer' => true, 'is_lecturer' => true,
'name' => fake()->name(),
]); ]);
$user->ownedTeams()
->save(Team::forceCreate([
'user_id' => $user->id,
'name' => explode(' ', $user->name, 2)[0]."'s Team",
'personal_team' => true,
]));
} }
// check if $k1 is in the database, if not, add it // check if $k1 is in the database, if not, add it
$loginKey = LoginKey::where('k1', $request->k1) $loginKey = LoginKey::where('k1', $request->k1)

View File

@@ -1,4 +1,5 @@
const defaultTheme = require('tailwindcss/defaultTheme') const defaultTheme = require('tailwindcss/defaultTheme')
const colors = require('tailwindcss/colors')
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
module.exports = { module.exports = {
@@ -46,6 +47,12 @@ module.exports = {
'800': '#673B04', '800': '#673B04',
'900': '#361F02' '900': '#361F02'
}, },
primary: colors.amber,
secondary: colors.slate,
positive: colors.emerald,
negative: colors.red,
warning: colors.amber,
info: colors.blue,
}, },
fontFamily: { fontFamily: {
sans: [ sans: [