Persists marketing attribution and registration metadata for new users across the three signup paths (email, Google, GitHub): - 5 utm_* columns + registration_ip on the users table - PreservesUtmParameters trait stores incoming utm_* query params on the register/redirect GET, retrieves them on the POST/callback — surviving the OAuth round-trip via session - request()->ip() captured at the controller layer Adds GitHub as a second OAuth provider: - GitHubController mirroring the Google one (now renamed from SocialLoginController for symmetry) - Settings → Authentication can connect/disconnect GitHub like Google - Single SocialLogin.vue component replaces the per-provider buttons on Login/Register, rendering each enabled provider plus a single "or continue with" divider UserFactory gains defaults for the new nullable columns so model strict-mode access in tests doesn't trip.
43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\User;
|
|
|
|
use App\Models\Account;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateUser
|
|
{
|
|
/**
|
|
* @param array{name: string, email: string, password?: string, google_id?: string, github_id?: string, email_verified_at?: \DateTimeInterface|null, is_invite?: bool, registration_ip?: string|null} $data
|
|
* @param array<string, string> $utmParameters
|
|
*/
|
|
public static function execute(array $data, array $utmParameters = []): User
|
|
{
|
|
return DB::transaction(function () use ($data, $utmParameters): User {
|
|
$isInviteRegistration = data_get($data, 'is_invite', false);
|
|
|
|
$account = Account::create([
|
|
'name' => data_get($data, 'name')."'s Account",
|
|
'billing_email' => data_get($data, 'email'),
|
|
]);
|
|
|
|
$user = User::create(array_merge([
|
|
'name' => data_get($data, 'name'),
|
|
'email' => data_get($data, 'email'),
|
|
'password' => data_get($data, 'password'),
|
|
'google_id' => data_get($data, 'google_id'),
|
|
'github_id' => data_get($data, 'github_id'),
|
|
'email_verified_at' => data_get($data, 'email_verified_at', $isInviteRegistration ? now() : null),
|
|
'account_id' => $account->id,
|
|
'registration_ip' => data_get($data, 'registration_ip'),
|
|
], $utmParameters));
|
|
|
|
$account->update(['owner_id' => $user->id]);
|
|
|
|
return $user;
|
|
});
|
|
}
|
|
}
|