Checkout: minimize registration data
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-06 09:23:01 +01:00
parent 29c3c42134
commit 33af04db1b
9 changed files with 105 additions and 157 deletions

View File

@@ -82,12 +82,12 @@ class CheckoutController extends Controller
// User erstellen // User erstellen
$user = User::create([ $user = User::create([
'email' => $validated['email'], 'email' => $validated['email'],
'username' => $validated['username'], 'username' => Str::lower($validated['email']),
'first_name' => $validated['first_name'], 'first_name' => $validated['first_name'],
'last_name' => $validated['last_name'], 'last_name' => $validated['last_name'],
'name' => trim($validated['first_name'].' '.$validated['last_name']), 'name' => trim($validated['first_name'].' '.$validated['last_name']),
'address' => $validated['address'], 'address' => $validated['address'] ?? null,
'phone' => $validated['phone'], 'phone' => $validated['phone'] ?? null,
'preferred_locale' => $validated['locale'] ?? null, 'preferred_locale' => $validated['locale'] ?? null,
'role' => 'user', 'role' => 'user',
'password' => Hash::make($validated['password']), 'password' => Hash::make($validated['password']),

View File

@@ -3,6 +3,7 @@
namespace App\Http\Requests\Checkout; namespace App\Http\Requests\Checkout;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password; use Illuminate\Validation\Rules\Password;
class CheckoutRegisterRequest extends FormRequest class CheckoutRegisterRequest extends FormRequest
@@ -23,13 +24,18 @@ class CheckoutRegisterRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'email' => ['required', 'email', 'max:255', 'unique:users,email'], 'email' => [
'username' => ['required', 'string', 'max:255', 'unique:users,username'], 'required',
'email',
'max:255',
Rule::unique('users', 'email'),
Rule::unique('users', 'username'),
],
'password' => ['required', 'confirmed', Password::defaults()], 'password' => ['required', 'confirmed', Password::defaults()],
'first_name' => ['required', 'string', 'max:255'], 'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'], 'last_name' => ['required', 'string', 'max:255'],
'address' => ['required', 'string', 'max:500'], 'address' => ['nullable', 'string', 'max:500'],
'phone' => ['required', 'string', 'max:255'], 'phone' => ['nullable', 'string', 'max:255'],
'package_id' => ['required', 'exists:packages,id'], 'package_id' => ['required', 'exists:packages,id'],
'terms' => ['required', 'accepted'], 'terms' => ['required', 'accepted'],
'privacy_consent' => ['required', 'accepted'], 'privacy_consent' => ['required', 'accepted'],
@@ -44,7 +50,6 @@ class CheckoutRegisterRequest extends FormRequest
{ {
return [ return [
'email.unique' => 'Diese E-Mail-Adresse wird bereits verwendet.', 'email.unique' => 'Diese E-Mail-Adresse wird bereits verwendet.',
'username.unique' => 'Dieser Benutzername ist bereits vergeben.',
'password.confirmed' => 'Die Passwortbestätigung stimmt nicht überein.', 'password.confirmed' => 'Die Passwortbestätigung stimmt nicht überein.',
'package_id.exists' => 'Das ausgewählte Paket ist ungültig.', 'package_id.exists' => 'Das ausgewählte Paket ist ungültig.',
'terms.accepted' => 'Bitte akzeptiere die Nutzungsbedingungen.', 'terms.accepted' => 'Bitte akzeptiere die Nutzungsbedingungen.',

View File

@@ -0,0 +1,52 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasColumn('users', 'username')) {
return;
}
$driver = DB::getDriverName();
if ($driver === 'mysql') {
DB::statement('ALTER TABLE users MODIFY username VARCHAR(255) NULL');
return;
}
if ($driver === 'pgsql') {
DB::statement('ALTER TABLE users ALTER COLUMN username TYPE VARCHAR(255)');
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
if (! Schema::hasColumn('users', 'username')) {
return;
}
$driver = DB::getDriverName();
if ($driver === 'mysql') {
DB::statement('ALTER TABLE users MODIFY username VARCHAR(32) NULL');
return;
}
if ($driver === 'pgsql') {
DB::statement('ALTER TABLE users ALTER COLUMN username TYPE VARCHAR(32)');
}
}
};

View File

@@ -2,7 +2,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { useForm, usePage } from '@inertiajs/react'; import { useForm, usePage } from '@inertiajs/react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import { LoaderCircle, User, Mail, Phone, Lock, MapPin } from 'lucide-react'; import { LoaderCircle, User, Mail, Lock } from 'lucide-react';
import { Dialog, DialogContent, DialogTitle, DialogDescription } from '@/components/ui/dialog'; import { Dialog, DialogContent, DialogTitle, DialogDescription } from '@/components/ui/dialog';
import type { GoogleProfilePrefill } from '../marketing/checkout/types'; import type { GoogleProfilePrefill } from '../marketing/checkout/types';
@@ -22,14 +22,11 @@ interface RegisterFormProps {
} }
type RegisterFormFields = { type RegisterFormFields = {
username: string;
email: string; email: string;
password: string; password: string;
password_confirmation: string; password_confirmation: string;
first_name: string; first_name: string;
last_name: string; last_name: string;
address: string;
phone: string;
privacy_consent: boolean; privacy_consent: boolean;
terms: boolean; terms: boolean;
package_id: number | null; package_id: number | null;
@@ -65,14 +62,11 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
const resolvedLocale = locale ?? page.props.locale ?? 'de'; const resolvedLocale = locale ?? page.props.locale ?? 'de';
const { data, setData, errors, clearErrors, reset, setError } = useForm<RegisterFormFields>({ const { data, setData, errors, clearErrors, reset, setError } = useForm<RegisterFormFields>({
username: '',
email: '', email: '',
password: '', password: '',
password_confirmation: '', password_confirmation: '',
first_name: '', first_name: '',
last_name: '', last_name: '',
address: '',
phone: '',
privacy_consent: false, privacy_consent: false,
terms: false, terms: false,
package_id: packageId || null, package_id: packageId || null,
@@ -87,7 +81,7 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
const registerEndpoint = '/checkout/register'; const registerEndpoint = '/checkout/register';
const requiredStringFields: Array<keyof RegisterFormFields> = useMemo(() => ( const requiredStringFields: Array<keyof RegisterFormFields> = useMemo(() => (
['first_name', 'last_name', 'username', 'email', 'password', 'password_confirmation', 'address', 'phone'] ['first_name', 'last_name', 'email', 'password', 'password_confirmation']
), []); ), []);
const isFormValid = useMemo(() => { const isFormValid = useMemo(() => {
@@ -121,27 +115,6 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
}; };
}, [prefill]); }, [prefill]);
const suggestedUsername = useMemo(() => {
if (prefill?.email) {
const localPart = prefill.email.split('@')[0];
if (localPart) {
return localPart.slice(0, 30);
}
}
const first = prefill?.given_name ?? prefill?.name?.split(' ')[0] ?? '';
const last = prefill?.family_name ?? prefill?.name?.split(' ').slice(1).join(' ') ?? '';
const combined = `${first}${last}`.trim();
if (!combined) {
return undefined;
}
return combined
.toLowerCase()
.replace(/[^a-z0-9]+/g, '')
.slice(0, 30) || undefined;
}, [prefill]);
useEffect(() => { useEffect(() => {
if (!prefill || prefillApplied) { if (!prefill || prefillApplied) {
return; return;
@@ -159,12 +132,8 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
setData('email', prefill.email); setData('email', prefill.email);
} }
if (suggestedUsername && !data.username) {
setData('username', suggestedUsername);
}
setPrefillApplied(true); setPrefillApplied(true);
}, [prefill, namePrefill.first, namePrefill.last, data.first_name, data.last_name, data.email, data.username, prefillApplied, setData, suggestedUsername]); }, [prefill, namePrefill.first, namePrefill.last, data.first_name, data.last_name, data.email, prefillApplied, setData]);
const submit = async (event: React.FormEvent) => { const submit = async (event: React.FormEvent) => {
event.preventDefault(); event.preventDefault();
@@ -357,81 +326,6 @@ export default function RegisterForm({ packageId, onSuccess, privacyHtml, locale
{errors.email && <p className="text-sm text-red-600 mt-1">{errors.email}</p>} {errors.email && <p className="text-sm text-red-600 mt-1">{errors.email}</p>}
</div> </div>
<div className="md:col-span-2">
<label htmlFor="address" className="block text-sm font-medium text-gray-700 mb-1">
{t('register.address')} {t('common:required')}
</label>
<div className="relative">
<MapPin className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 w-5 h-5" />
<input
id="address"
name="address"
type="text"
required
value={data.address}
onChange={(e) => {
setData('address', e.target.value);
if (e.target.value.trim() && errors.address) {
clearErrors('address');
}
}}
className={`block w-full pl-10 pr-3 py-3 border rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-[#FFB6C1] focus:border-[#FFB6C1] sm:text-sm ${errors.address ? 'border-red-500' : 'border-gray-300'}`}
placeholder={t('register.address_placeholder')}
/>
</div>
{errors.address && <p className="text-sm text-red-600 mt-1">{errors.address}</p>}
</div>
<div className="md:col-span-1">
<label htmlFor="phone" className="block text-sm font-medium text-gray-700 mb-1">
{t('register.phone')} {t('common:required')}
</label>
<div className="relative">
<Phone className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 w-5 h-5" />
<input
id="phone"
name="phone"
type="tel"
required
value={data.phone}
onChange={(e) => {
setData('phone', e.target.value);
if (e.target.value.trim() && errors.phone) {
clearErrors('phone');
}
}}
className={`block w-full pl-10 pr-3 py-3 border rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-[#FFB6C1] focus:border-[#FFB6C1] sm:text-sm ${errors.phone ? 'border-red-500' : 'border-gray-300'}`}
placeholder={t('register.phone_placeholder')}
/>
</div>
{errors.phone && <p className="text-sm text-red-600 mt-1">{errors.phone}</p>}
</div>
<div className="md:col-span-1">
<label htmlFor="username" className="block text-sm font-medium text-gray-700 mb-1">
{t('register.username')} {t('common:required')}
</label>
<div className="relative">
<User className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 w-5 h-5" />
<input
id="username"
name="username"
type="text"
required
value={data.username}
onChange={(e) => {
setData('username', e.target.value);
if (e.target.value.trim() && errors.username) {
clearErrors('username');
}
}}
className={`block w-full pl-10 pr-3 py-3 border rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-[#FFB6C1] focus:border-[#FFB6C1] sm:text-sm ${errors.username ? 'border-red-500' : 'border-gray-300'}`}
placeholder={t('register.username_placeholder')}
/>
</div>
{errors.username && <p className="text-sm text-red-600 mt-1">{errors.username}</p>}
</div>
<div className="md:col-span-1"> <div className="md:col-span-1">
<label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-1"> <label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-1">
{t('register.password')} {t('common:required')} {t('register.password')} {t('common:required')}

View File

@@ -15,14 +15,11 @@ class CheckoutAuthTest extends TestCase
private function registrationPayload(Package $package, array $overrides = []): array private function registrationPayload(Package $package, array $overrides = []): array
{ {
return array_merge([ return array_merge([
'username' => 'testuser',
'email' => 'test@example.com', 'email' => 'test@example.com',
'password' => 'password123', 'password' => 'password123',
'password_confirmation' => 'password123', 'password_confirmation' => 'password123',
'first_name' => 'Test', 'first_name' => 'Test',
'last_name' => 'User', 'last_name' => 'User',
'address' => 'Test Address 123',
'phone' => '+49123456789',
'terms' => true, 'terms' => true,
'privacy_consent' => true, 'privacy_consent' => true,
'package_id' => $package->id, 'package_id' => $package->id,
@@ -169,7 +166,7 @@ class CheckoutAuthTest extends TestCase
]); ]);
$this->assertDatabaseHas('users', [ $this->assertDatabaseHas('users', [
'username' => 'testuser', 'username' => 'test@example.com',
'email' => 'test@example.com', 'email' => 'test@example.com',
'first_name' => 'Test', 'first_name' => 'Test',
'last_name' => 'User', 'last_name' => 'User',
@@ -202,7 +199,7 @@ class CheckoutAuthTest extends TestCase
]); ]);
$this->assertDatabaseHas('users', [ $this->assertDatabaseHas('users', [
'username' => 'testuser', 'username' => 'test@example.com',
'email' => 'test@example.com', 'email' => 'test@example.com',
'pending_purchase' => true, 'pending_purchase' => true,
]); ]);
@@ -215,14 +212,11 @@ class CheckoutAuthTest extends TestCase
$package = Package::factory()->create(); $package = Package::factory()->create();
$response = $this->postJson(route('checkout.register'), $this->registrationPayload($package, [ $response = $this->postJson(route('checkout.register'), $this->registrationPayload($package, [
'username' => '',
'email' => 'invalid-email', 'email' => 'invalid-email',
'password' => '123', 'password' => '123',
'password_confirmation' => '456', 'password_confirmation' => '456',
'first_name' => '', 'first_name' => '',
'last_name' => '', 'last_name' => '',
'address' => '',
'phone' => '',
'terms' => false, 'terms' => false,
'privacy_consent' => false, 'privacy_consent' => false,
])); ]));
@@ -230,13 +224,10 @@ class CheckoutAuthTest extends TestCase
$response->assertStatus(422) $response->assertStatus(422)
->assertJsonStructure([ ->assertJsonStructure([
'errors' => [ 'errors' => [
'username' => [],
'email' => [], 'email' => [],
'password' => [], 'password' => [],
'first_name' => [], 'first_name' => [],
'last_name' => [], 'last_name' => [],
'address' => [],
'phone' => [],
'terms' => [], 'terms' => [],
'privacy_consent' => [], 'privacy_consent' => [],
], ],
@@ -256,14 +247,12 @@ class CheckoutAuthTest extends TestCase
$package = Package::factory()->create(); $package = Package::factory()->create();
$response = $this->postJson(route('checkout.register'), $this->registrationPayload($package, [ $response = $this->postJson(route('checkout.register'), $this->registrationPayload($package, [
'username' => 'existinguser',
'email' => 'existing@example.com', 'email' => 'existing@example.com',
])); ]));
$response->assertStatus(422) $response->assertStatus(422)
->assertJsonStructure([ ->assertJsonStructure([
'errors' => [ 'errors' => [
'username' => [],
'email' => [], 'email' => [],
], ],
]); ]);
@@ -274,14 +263,11 @@ class CheckoutAuthTest extends TestCase
public function test_checkout_register_without_package() public function test_checkout_register_without_package()
{ {
$response = $this->postJson(route('checkout.register'), [ $response = $this->postJson(route('checkout.register'), [
'username' => 'testuser',
'email' => 'test@example.com', 'email' => 'test@example.com',
'password' => 'password123', 'password' => 'password123',
'password_confirmation' => 'password123', 'password_confirmation' => 'password123',
'first_name' => 'Test', 'first_name' => 'Test',
'last_name' => 'User', 'last_name' => 'User',
'address' => 'Test Address 123',
'phone' => '+49123456789',
'terms' => true, 'terms' => true,
'privacy_consent' => true, 'privacy_consent' => true,
'locale' => 'de', 'locale' => 'de',
@@ -368,13 +354,10 @@ class CheckoutAuthTest extends TestCase
$response->assertStatus(422) $response->assertStatus(422)
->assertJsonStructure([ ->assertJsonStructure([
'errors' => [ 'errors' => [
'username' => [],
'email' => [], 'email' => [],
'password' => [], 'password' => [],
'first_name' => [], 'first_name' => [],
'last_name' => [], 'last_name' => [],
'address' => [],
'phone' => [],
'package_id' => [], 'package_id' => [],
'terms' => [], 'terms' => [],
'privacy_consent' => [], 'privacy_consent' => [],
@@ -457,18 +440,23 @@ class CheckoutAuthTest extends TestCase
$this->assertGuest(); $this->assertGuest();
} }
public function test_checkout_register_username_too_long() public function test_checkout_register_email_conflicts_with_existing_username()
{ {
User::factory()->create([
'username' => 'taken@example.com',
'email' => 'other@example.com',
]);
$package = Package::factory()->create(); $package = Package::factory()->create();
$response = $this->postJson(route('checkout.register'), $this->registrationPayload($package, [ $response = $this->postJson(route('checkout.register'), $this->registrationPayload($package, [
'username' => str_repeat('a', 256), 'email' => 'taken@example.com',
])); ]));
$response->assertStatus(422) $response->assertStatus(422)
->assertJsonStructure([ ->assertJsonStructure([
'errors' => [ 'errors' => [
'username' => [], 'email' => [],
], ],
]); ]);

View File

@@ -20,13 +20,10 @@ class CheckoutRegisterRoleTest extends TestCase
$payload = [ $payload = [
'email' => 'buyer@example.test', 'email' => 'buyer@example.test',
'username' => 'buyer',
'password' => 'Password!123', 'password' => 'Password!123',
'password_confirmation' => 'Password!123', 'password_confirmation' => 'Password!123',
'first_name' => 'Soren', 'first_name' => 'Soren',
'last_name' => 'Eberhardt', 'last_name' => 'Eberhardt',
'address' => 'Example Street 1',
'phone' => '123456789',
'package_id' => $package->id, 'package_id' => $package->id,
'terms' => true, 'terms' => true,
'privacy_consent' => true, 'privacy_consent' => true,
@@ -41,5 +38,6 @@ class CheckoutRegisterRoleTest extends TestCase
$this->assertNotNull($user); $this->assertNotNull($user);
$this->assertSame('user', $user->role); $this->assertSame('user', $user->role);
$this->assertSame('buyer@example.test', $user->username);
} }
} }

View File

@@ -26,14 +26,11 @@ class FullUserFlowTest extends TestCase
$freePackage = Package::factory()->endcustomer()->create(['price' => 0]); $freePackage = Package::factory()->endcustomer()->create(['price' => 0]);
$registrationData = [ $registrationData = [
'username' => 'flowuser',
'email' => 'flow@example.com', 'email' => 'flow@example.com',
'password' => 'Password123!', 'password' => 'Password123!',
'password_confirmation' => 'Password123!', 'password_confirmation' => 'Password123!',
'first_name' => 'Max', 'first_name' => 'Max',
'last_name' => 'Mustermann', 'last_name' => 'Mustermann',
'address' => 'Musterstr. 1',
'phone' => '+49123456789',
'privacy_consent' => true, 'privacy_consent' => true,
'terms' => true, 'terms' => true,
'package_id' => $freePackage->id, 'package_id' => $freePackage->id,
@@ -132,14 +129,11 @@ class FullUserFlowTest extends TestCase
// Schritt 1: Fehlgeschlagene Registrierung (kein Consent) // Schritt 1: Fehlgeschlagene Registrierung (kein Consent)
$response = $this->post('/de/register', [ $response = $this->post('/de/register', [
'name' => 'Error User', 'name' => 'Error User',
'username' => 'erroruser',
'email' => 'error@example.com', 'email' => 'error@example.com',
'password' => 'Password123!', 'password' => 'Password123!',
'password_confirmation' => 'Password123!', 'password_confirmation' => 'Password123!',
'first_name' => 'Max', 'first_name' => 'Max',
'last_name' => 'Mustermann', 'last_name' => 'Mustermann',
'address' => 'Musterstr. 1',
'phone' => '+49123456789',
'privacy_consent' => false, 'privacy_consent' => false,
]); ]);

View File

@@ -171,12 +171,20 @@ async function completeRegistrationOrLogin(page: Page, credentials: { email: str
await page.fill('input[name="first_name"]', 'Play'); await page.fill('input[name="first_name"]', 'Play');
await page.fill('input[name="last_name"]', 'Wright'); await page.fill('input[name="last_name"]', 'Wright');
await page.fill('input[name="email"]', credentials.email); await page.fill('input[name="email"]', credentials.email);
await page.fill('input[name="address"]', 'Teststrasse 1, 12345 Berlin'); const addressInput = page.locator('input[name="address"]');
await page.fill('input[name="phone"]', '+49123456789'); if (await addressInput.isVisible()) {
await addressInput.fill('Teststrasse 1, 12345 Berlin');
}
const username = credentials.email.split('@')[0]?.replace(/[^a-z0-9]+/gi, '-') ?? `playwright-${Date.now()}`; const phoneInput = page.locator('input[name="phone"]');
await page.fill('input[name="username"]', username); if (await phoneInput.isVisible()) {
await phoneInput.fill('+49123456789');
}
const usernameInput = page.locator('input[name="username"]');
if (await usernameInput.isVisible()) {
await usernameInput.fill(credentials.email);
}
await page.fill('input[name="password"]', credentials.password); await page.fill('input[name="password"]', credentials.password);
await page.fill('input[name="password_confirmation"]', credentials.password); await page.fill('input[name="password_confirmation"]', credentials.password);

View File

@@ -18,8 +18,6 @@ test.describe('Standard package checkout with Paddle completion', () => {
const unique = Date.now(); const unique = Date.now();
const email = `checkout+${unique}@example.test`; const email = `checkout+${unique}@example.test`;
const password = 'Password123!'; const password = 'Password123!';
const username = `playwright-${unique}`;
await page.addInitScript(() => { await page.addInitScript(() => {
window.__openedWindows = []; window.__openedWindows = [];
const originalOpen = window.open; const originalOpen = window.open;
@@ -87,9 +85,20 @@ test.describe('Standard package checkout with Paddle completion', () => {
await page.fill('input[name="first_name"]', 'Playwright'); await page.fill('input[name="first_name"]', 'Playwright');
await page.fill('input[name="last_name"]', 'Tester'); await page.fill('input[name="last_name"]', 'Tester');
await page.fill('input[name="email"]', email); await page.fill('input[name="email"]', email);
await page.fill('input[name="phone"]', '+49123456789'); const addressInput = page.locator('input[name="address"]');
await page.fill('input[name="address"]', 'Teststr. 1, 12345 Berlin'); if (await addressInput.isVisible()) {
await page.fill('input[name="username"]', username); await addressInput.fill('Teststr. 1, 12345 Berlin');
}
const phoneInput = page.locator('input[name="phone"]');
if (await phoneInput.isVisible()) {
await phoneInput.fill('+49123456789');
}
const usernameInput = page.locator('input[name="username"]');
if (await usernameInput.isVisible()) {
await usernameInput.fill(email);
}
await page.fill('input[name="password"]', password); await page.fill('input[name="password"]', password);
await page.fill('input[name="password_confirmation"]', password); await page.fill('input[name="password_confirmation"]', password);
await page.check('input[name="privacy_consent"]'); await page.check('input[name="privacy_consent"]');