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.
82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Account;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends Factory<User>
|
|
*/
|
|
class UserFactory extends Factory
|
|
{
|
|
/**
|
|
* The current password being used by the factory.
|
|
*/
|
|
protected static ?string $password;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => fake()->name(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'email_verified_at' => now(),
|
|
'password' => static::$password ??= Hash::make('password'),
|
|
'google_id' => null,
|
|
'github_id' => null,
|
|
'remember_token' => Str::random(10),
|
|
'account_id' => Account::factory(),
|
|
'current_workspace_id' => null,
|
|
'two_factor_secret' => null,
|
|
'two_factor_recovery_codes' => null,
|
|
'two_factor_confirmed_at' => null,
|
|
'utm_source' => null,
|
|
'utm_medium' => null,
|
|
'utm_campaign' => null,
|
|
'utm_term' => null,
|
|
'utm_content' => null,
|
|
'registration_ip' => null,
|
|
];
|
|
}
|
|
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (User $user) {
|
|
if ($user->account_id && ! $user->account?->owner_id) {
|
|
$user->account->update(['owner_id' => $user->id]);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Indicate that the model's email address should be unverified.
|
|
*/
|
|
public function unverified(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'email_verified_at' => null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the model has two-factor authentication configured.
|
|
*/
|
|
public function withTwoFactor(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'two_factor_secret' => encrypt('secret'),
|
|
'two_factor_recovery_codes' => encrypt(json_encode(['recovery-code-1'])),
|
|
'two_factor_confirmed_at' => now(),
|
|
]);
|
|
}
|
|
}
|