mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
ln auth added
This commit is contained in:
@@ -17,3 +17,32 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
|
||||
Route::get('/lnurl-auth-callback', function (\Illuminate\Http\Request $request) {
|
||||
if (lnurl\auth($request->k1, $request->signature, $request->wallet_public_key)) {
|
||||
// find User by $wallet_public_key
|
||||
$user = User::where('public_key', $request->key)
|
||||
->first();
|
||||
if (!$user) {
|
||||
// create User
|
||||
$user = User::create([
|
||||
'public_key' => $request->wallet_public_key,
|
||||
'is_lecturer' => true,
|
||||
]);
|
||||
}
|
||||
// check if $k1 is in the database, if not, add it
|
||||
$loginKey = LoginKey::where('k1', $request->k1)
|
||||
->first();
|
||||
if (!$loginKey) {
|
||||
LoginKey::create([
|
||||
'k1' => $request->k1,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'OK']);
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'ERROR', 'reason' => 'Signature was NOT VERIFIED']);
|
||||
})
|
||||
->name('auth.ln.callback');
|
||||
|
||||
Reference in New Issue
Block a user