Save workspace changes

This commit is contained in:
2026-04-18 17:02:56 +02:00
parent f02ea9a711
commit 87d60af5a9
4220 changed files with 1388603 additions and 1554 deletions

View File

@@ -2,15 +2,21 @@
namespace App\Http\Requests\Auth;
use App\Models\User;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class LoginRequest extends FormRequest
{
private ?User $authenticatedUser = null;
private string $authenticatedVia = 'email';
/**
* Determine if the user is authorized to make this request.
*/
@@ -27,7 +33,7 @@ class LoginRequest extends FormRequest
public function rules(): array
{
return [
'email' => ['required', 'string', 'email'],
'email' => ['required', 'string'],
'password' => ['required', 'string'],
];
}
@@ -41,7 +47,25 @@ class LoginRequest extends FormRequest
{
$this->ensureIsNotRateLimited();
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
$identifier = strtolower(trim((string) $this->input('email')));
$password = (string) $this->input('password');
$user = User::query()
->whereRaw('LOWER(email) = ?', [$identifier])
->first();
$authenticatedVia = 'email';
if (! $user) {
$candidate = User::query()
->whereRaw('LOWER(username) = ?', [$identifier])
->first();
if ($candidate?->supportsUsernameLogin()) {
$user = $candidate;
$authenticatedVia = 'username';
}
}
if (! $user || ! Hash::check($password, (string) $user->password)) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
@@ -49,9 +73,23 @@ class LoginRequest extends FormRequest
]);
}
Auth::login($user, $this->boolean('remember'));
$this->authenticatedUser = $user;
$this->authenticatedVia = $authenticatedVia;
RateLimiter::clear($this->throttleKey());
}
public function authenticatedUser(): ?User
{
return $this->authenticatedUser;
}
public function authenticatedViaUsername(): bool
{
return $this->authenticatedVia === 'username';
}
/**
* Ensure the login request is not rate limited.
*

View File

@@ -35,6 +35,12 @@ class RequestEmailChangeRequest extends FormRequest
'max:255',
Rule::unique(User::class, 'email')->ignore((int) $this->user()->id),
function (string $attribute, mixed $value, \Closure $fail): void {
if (User::isEmailLoginUpgradePlaceholder((string) $value)) {
$fail('Please enter a real email address you can access.');
return;
}
if (strtolower((string) $value) === strtolower((string) $this->user()->email)) {
$fail('Please enter a different email address.');
}

View File

@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Worlds;
use App\Models\World;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreWorldRequest extends FormRequest
{
/**
* @return array<int, string>
*/
protected function reservedSlugs(): array
{
return ['create'];
}
public function authorize(): bool
{
return (bool) $this->user();
}
public function rules(): array
{
$sectionKeys = array_keys((array) config('worlds.sections', []));
$relationTypes = array_keys((array) config('worlds.relation_types', []));
return [
'title' => ['required', 'string', 'max:180'],
'slug' => ['nullable', 'string', 'max:180', 'regex:/^[a-z0-9]+(?:-[a-z0-9]+)*$/', Rule::notIn($this->reservedSlugs())],
'tagline' => ['nullable', 'string', 'max:220'],
'summary' => ['nullable', 'string', 'max:320'],
'description' => ['nullable', 'string', 'max:20000'],
'cover_path' => ['nullable', 'string', 'max:2048'],
'theme_key' => ['nullable', 'string', 'max:80'],
'accent_color' => ['nullable', 'string', 'max:16'],
'accent_color_secondary' => ['nullable', 'string', 'max:16'],
'background_motif' => ['nullable', 'string', 'max:80'],
'icon_name' => ['nullable', 'string', 'max:120'],
'status' => ['required', Rule::in([World::STATUS_DRAFT, World::STATUS_PUBLISHED, World::STATUS_ARCHIVED])],
'type' => ['required', Rule::in([World::TYPE_SEASONAL, World::TYPE_EVENT, World::TYPE_CAMPAIGN, World::TYPE_TRIBUTE])],
'starts_at' => ['nullable', 'date'],
'ends_at' => ['nullable', 'date', 'after_or_equal:starts_at'],
'accepts_submissions' => ['nullable', 'boolean'],
'participation_mode' => ['nullable', Rule::in([
World::PARTICIPATION_MODE_MANUAL_APPROVAL,
World::PARTICIPATION_MODE_AUTO_ADD,
World::PARTICIPATION_MODE_CLOSED,
])],
'submission_starts_at' => ['nullable', 'date'],
'submission_ends_at' => ['nullable', 'date', 'after_or_equal:submission_starts_at'],
'submission_note_enabled' => ['nullable', 'boolean'],
'community_section_enabled' => ['nullable', 'boolean'],
'allow_readd_after_removal' => ['nullable', 'boolean'],
'is_featured' => ['nullable', 'boolean'],
'is_recurring' => ['nullable', 'boolean'],
'recurrence_key' => ['nullable', 'string', 'max:120'],
'recurrence_rule' => ['nullable', 'string', 'max:160'],
'edition_year' => ['nullable', 'integer', 'between:2000,2100'],
'cta_label' => ['nullable', 'string', 'max:120'],
'cta_url' => ['nullable', 'url', 'max:2048'],
'badge_label' => ['nullable', 'string', 'max:120'],
'badge_description' => ['nullable', 'string', 'max:2000'],
'submission_guidelines' => ['nullable', 'string', 'max:5000'],
'badge_url' => ['nullable', 'url', 'max:2048'],
'seo_title' => ['nullable', 'string', 'max:255'],
'seo_description' => ['nullable', 'string', 'max:300'],
'og_image_path' => ['nullable', 'string', 'max:2048'],
'related_tags_json' => ['nullable', 'array', 'max:12'],
'related_tags_json.*' => ['string', 'max:40'],
'section_order_json' => ['nullable', 'array'],
'section_order_json.*' => ['string', Rule::in($sectionKeys)],
'section_visibility_json' => ['nullable', 'array'],
'section_visibility_json.*' => ['boolean'],
'parent_world_id' => ['nullable', 'integer', 'exists:worlds,id'],
'published_at' => ['nullable', 'date'],
'relations' => ['nullable', 'array', 'max:60'],
'relations.*.section_key' => ['required_with:relations', 'string', Rule::in($sectionKeys)],
'relations.*.related_type' => ['required_with:relations', 'string', Rule::in($relationTypes)],
'relations.*.related_id' => ['required_with:relations', 'integer', 'min:1'],
'relations.*.context_label' => ['nullable', 'string', 'max:120'],
'relations.*.sort_order' => ['nullable', 'integer', 'min:0'],
'relations.*.is_featured' => ['nullable', 'boolean'],
];
}
public function withValidator($validator): void
{
$validator->after(function ($validator): void {
$sections = (array) config('worlds.sections', []);
if ($this->boolean('is_recurring')) {
if (trim((string) $this->input('recurrence_key', '')) === '') {
$validator->errors()->add('recurrence_key', 'Recurring worlds need a recurrence key such as halloween or retro-month.');
}
if (! is_numeric($this->input('edition_year'))) {
$validator->errors()->add('edition_year', 'Recurring worlds need an edition year.');
}
}
$recurrenceKey = trim((string) $this->input('recurrence_key', ''));
$editionYear = $this->input('edition_year');
if ($recurrenceKey !== '' && ! preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $recurrenceKey)) {
$validator->errors()->add('recurrence_key', 'Use lowercase letters, numbers, and dashes only.');
}
if ($this->boolean('is_recurring') && $recurrenceKey !== '' && is_numeric($editionYear)) {
$worldId = $this->route('world')?->id;
$exists = World::query()
->where('recurrence_key', $recurrenceKey)
->where('edition_year', (int) $editionYear)
->when($worldId, fn (Builder $builder) => $builder->where('id', '!=', $worldId))
->exists();
if ($exists) {
$validator->errors()->add('edition_year', 'That recurrence key already has an edition for this year.');
}
}
foreach ((array) $this->input('relations', []) as $index => $relation) {
$sectionKey = (string) ($relation['section_key'] ?? '');
$relatedType = (string) ($relation['related_type'] ?? '');
$allowed = (array) ($sections[$sectionKey]['relation_types'] ?? []);
if ($sectionKey !== '' && $relatedType !== '' && $allowed !== [] && ! in_array($relatedType, $allowed, true)) {
$validator->errors()->add("relations.{$index}.related_type", 'That entity type cannot be attached to the selected section.');
}
}
if ((string) $this->input('participation_mode') === World::PARTICIPATION_MODE_CLOSED && $this->boolean('accepts_submissions')) {
$validator->errors()->add('accepts_submissions', 'Closed worlds cannot accept creator submissions.');
}
});
}
}

View File

@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Worlds;
class UpdateWorldRequest extends StoreWorldRequest
{
}