feat: Phase 2 - page CRUD, subscriber management, user management
This commit is contained in:
32
app/Http/Requests/Admin/IndexSubscriberRequest.php
Normal file
32
app/Http/Requests/Admin/IndexSubscriberRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Models\PreregistrationPage;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class IndexSubscriberRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$page = $this->route('page');
|
||||
if (! $page instanceof PreregistrationPage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->user()?->can('view', $page) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'search' => ['nullable', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Admin/StorePreregistrationPageRequest.php
Normal file
32
app/Http/Requests/Admin/StorePreregistrationPageRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Models\PreregistrationPage;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StorePreregistrationPageRequest extends FormRequest
|
||||
{
|
||||
use ValidatesPreregistrationPageInput;
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->can('create', PreregistrationPage::class) ?? false;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->preparePreregistrationPageFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return $this->preregistrationPageRules();
|
||||
}
|
||||
}
|
||||
32
app/Http/Requests/Admin/StoreUserRequest.php
Normal file
32
app/Http/Requests/Admin/StoreUserRequest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class StoreUserRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->can('create', User::class) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)],
|
||||
'password' => ['required', 'confirmed', Password::defaults()],
|
||||
'role' => ['required', Rule::in(['superadmin', 'user'])],
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Http/Requests/Admin/UpdatePreregistrationPageRequest.php
Normal file
36
app/Http/Requests/Admin/UpdatePreregistrationPageRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdatePreregistrationPageRequest extends FormRequest
|
||||
{
|
||||
use ValidatesPreregistrationPageInput;
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
$page = $this->route('page');
|
||||
if ($page === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->user()?->can('update', $page) ?? false;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->preparePreregistrationPageFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return $this->preregistrationPageRules();
|
||||
}
|
||||
}
|
||||
54
app/Http/Requests/Admin/UpdateUserRequest.php
Normal file
54
app/Http/Requests/Admin/UpdateUserRequest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class UpdateUserRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
$user = $this->route('user');
|
||||
if (! $user instanceof User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->user()?->can('update', $user) ?? false;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->input('password') === '' || $this->input('password') === null) {
|
||||
$this->merge(['password' => null]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var User $target */
|
||||
$target = $this->route('user');
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($target->id),
|
||||
],
|
||||
'password' => ['nullable', 'confirmed', Password::defaults()],
|
||||
'role' => ['required', Rule::in(['superadmin', 'user'])],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
trait ValidatesPreregistrationPageInput
|
||||
{
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
protected function preregistrationPageRules(): array
|
||||
{
|
||||
return [
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'heading' => ['required', 'string', 'max:255'],
|
||||
'intro_text' => ['nullable', 'string'],
|
||||
'thank_you_message' => ['nullable', 'string'],
|
||||
'expired_message' => ['nullable', 'string'],
|
||||
'ticketshop_url' => ['nullable', 'string', 'url:http,https', 'max:255'],
|
||||
'start_date' => ['required', 'date'],
|
||||
'end_date' => ['required', 'date', 'after:start_date'],
|
||||
'phone_enabled' => ['sometimes', 'boolean'],
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
'background_image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:5120'],
|
||||
'logo_image' => ['nullable', 'file', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function preparePreregistrationPageFields(): void
|
||||
{
|
||||
$ticketshop = $this->input('ticketshop_url');
|
||||
$ticketshopNormalized = null;
|
||||
if (is_string($ticketshop) && trim($ticketshop) !== '') {
|
||||
$ticketshopNormalized = trim($ticketshop);
|
||||
}
|
||||
|
||||
$this->merge([
|
||||
'phone_enabled' => $this->boolean('phone_enabled'),
|
||||
'is_active' => $this->boolean('is_active'),
|
||||
'ticketshop_url' => $ticketshopNormalized,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user