yoco updated to use webhook

This commit is contained in:
twotalesanimation
2025-12-29 14:43:24 +02:00
parent 6de01c13c5
commit 00b8ff77b2
123 changed files with 6959 additions and 12669 deletions
@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
class GoogleAuthController extends Controller
{
/**
* Redirect to Google OAuth
*/
public function redirect()
{
return Socialite::driver('google')->redirect();
}
/**
* Handle Google OAuth callback
*/
public function callback()
{
try {
$googleUser = Socialite::driver('google')->user();
// Find or create user
$user = User::firstOrCreate(
['email' => $googleUser->getEmail()],
[
'name' => $googleUser->getName(),
'google_id' => $googleUser->getId(),
'email_verified_at' => now(),
// Set a random password so the row passes DB constraints; not used for login
'password' => Str::random(32),
]
);
// Update Google ID if not already set
if (!$user->google_id) {
$user->update(['google_id' => $googleUser->getId()]);
}
Auth::login($user, remember: true);
return redirect()->intended('/');
} catch (\Exception $e) {
Log::error('Google OAuth callback failed', [
'error' => $e->getMessage(),
'exception' => $e,
]);
return redirect('/login')->with('error', 'Failed to authenticate with Google. Please try again.');
}
}
/**
* Logout user
*/
public function logout()
{
Log::info('User logging out', [
'user_id' => optional(Auth::user())->id,
'email' => optional(Auth::user())->email,
]);
Auth::logout();
request()->session()->invalidate();
request()->session()->regenerateToken();
return redirect('/');
}
}