fix(auth/admin): atomic user+customer signup; Rule::in for country validation (comma-safe)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>feat/portal-design
parent
6ca1e3fba5
commit
22cbe9ac39
|
|
@ -4,6 +4,7 @@ namespace App\Actions\Fortify;
|
|||
|
||||
use App\Models\Customer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
|
@ -39,15 +40,16 @@ class CreateNewUser implements CreatesNewUsers
|
|||
'password' => $this->passwordRules(),
|
||||
])->validate();
|
||||
|
||||
// Create the user and its linked customer atomically — a public signup is
|
||||
// a customer, and the portal (Billing::purchase, Settings, …) needs one.
|
||||
// Either both exist or neither, so a failure never orphans a user.
|
||||
return DB::transaction(function () use ($input) {
|
||||
$user = User::create([
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'password' => Hash::make($input['password']),
|
||||
]);
|
||||
|
||||
// A public signup is a customer — create and link the record now so the
|
||||
// portal (Billing::purchase, Settings, …) has a customer to work with
|
||||
// before they buy a package.
|
||||
Customer::query()->create([
|
||||
'user_id' => $user->id,
|
||||
'name' => $input['name'],
|
||||
|
|
@ -57,5 +59,6 @@ class CreateNewUser implements CreatesNewUsers
|
|||
]);
|
||||
|
||||
return $user;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\Datacenter;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
|
@ -32,7 +33,7 @@ class Datacenters extends Component
|
|||
$data = $this->validate([
|
||||
'code' => 'required|string|max:8|alpha_dash|unique:datacenters,code',
|
||||
'name' => 'required|string|max:255',
|
||||
'location' => 'nullable|in:'.implode(',', array_keys((array) config('countries'))),
|
||||
'location' => ['nullable', Rule::in(array_keys((array) config('countries')))],
|
||||
]);
|
||||
|
||||
Datacenter::create([
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\Datacenter;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Validate;
|
||||
use LivewireUI\Modal\ModalComponent;
|
||||
|
||||
|
|
@ -51,7 +52,7 @@ class EditDatacenter extends ModalComponent
|
|||
}
|
||||
$data = $this->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'location' => 'nullable|in:'.implode(',', $allowed),
|
||||
'location' => ['nullable', Rule::in($allowed)], // array form — a legacy value may contain commas
|
||||
]);
|
||||
|
||||
Datacenter::query()->where('uuid', $this->uuid)->update([
|
||||
|
|
|
|||
Loading…
Reference in New Issue