- Refactor WorkspacePolicy to use pivot role instead of workspace.user_id - Add manageBilling policy (owner only) to BillingController - Fix ApiKeyController authorization (view → manageTeam for store/destroy) - Fix WorkspaceInviteController using workspace.user_id for owner checks - Fix WorkspaceController settings is_owner using workspace.user_id - Create PostAction enum for UpdatePost/PostController action strings - Create ApiToken\Status enum - Add User::SUBSCRIPTION_NAME constant, replace all hardcoded 'default' - Convert wantsEmailFor to accept NotificationType enum - Convert all $data[] to data_get() across publishers, controllers, jobs - Fix SocialLoginController callback missing try/catch - Fix SocialController::toggleActive missing workspace null check - Fix UpdatePost NPE on meta merge when postPlatform not found - Remove HTML5 required attributes from form inputs - Convert function declarations to arrow functions in Vue components - Replace hardcoded URLs with Wayfinder route helpers - Replace new Date() with dayjs - Add 16 new test files covering policies, authorization, publishing
66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Actions\User\CreateUser;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
class SocialLoginController extends Controller
|
|
{
|
|
public function redirect(): RedirectResponse
|
|
{
|
|
return Socialite::driver('google-auth')->redirect();
|
|
}
|
|
|
|
public function callback(): RedirectResponse
|
|
{
|
|
try {
|
|
$googleUser = Socialite::driver('google-auth')->user();
|
|
} catch (\Exception) {
|
|
return redirect()->route('login');
|
|
}
|
|
|
|
$user = User::where('email', $googleUser->getEmail())->first();
|
|
|
|
if ($user) {
|
|
return $this->loginExistingUser($user);
|
|
}
|
|
|
|
return $this->registerNewUser($googleUser);
|
|
}
|
|
|
|
private function loginExistingUser(User $user): RedirectResponse
|
|
{
|
|
if (! $user->hasVerifiedEmail()) {
|
|
$user->markEmailAsVerified();
|
|
}
|
|
|
|
Auth::login($user, remember: true);
|
|
|
|
return redirect()->route('app.home');
|
|
}
|
|
|
|
private function registerNewUser(\Laravel\Socialite\Contracts\User $googleUser): RedirectResponse
|
|
{
|
|
$user = CreateUser::execute([
|
|
'name' => $googleUser->getName(),
|
|
'email' => $googleUser->getEmail(),
|
|
'email_verified_at' => now(),
|
|
]);
|
|
|
|
event(new Registered($user));
|
|
|
|
Auth::login($user, remember: true);
|
|
|
|
session()->flash('auth_provider', 'google');
|
|
|
|
return redirect()->route('register.success');
|
|
}
|
|
}
|