Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s

- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,19 @@
<?php
namespace App\Actions\Fortify;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Validation\Rules\Password;
trait PasswordValidationRules
{
/**
* Get the validation rules used to validate passwords.
*
* @return array<int, Rule|array<mixed>|string>
*/
protected function passwordRules(): array
{
return ['required', 'string', Password::default(), 'confirmed'];
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
class ResetUserPassword implements ResetsUserPasswords
{
use PasswordValidationRules;
/**
* Validate and reset the user's forgotten password.
*
* @param array<string, string> $input
*
* @throws ValidationException
*/
public function reset(User $user, array $input): void
{
Validator::make($input, [
'password' => $this->passwordRules(),
])->validate();
$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
class UpdateUserPassword implements UpdatesUserPasswords
{
use PasswordValidationRules;
/**
* Validate and update the user's password.
*
* @param array<string, string> $input
*
* @throws ValidationException
*/
public function update(User $user, array $input): void
{
Validator::make($input, [
'current_password' => ['required', 'string', 'current_password:web'],
'password' => $this->passwordRules(),
], [
'current_password.current_password' => __('The provided password does not match your current password.'),
])->validateWithBag('updatePassword');
$user->forceFill([
'password' => Hash::make($input['password']),
])->save();
}
}

View file

@ -0,0 +1,101 @@
<?php
namespace App\Filament\Pages;
use App\Support\Branding;
use App\Support\Settings;
use BackedEnum;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Illuminate\Support\Facades\Storage;
use UnitEnum;
/**
* Basis-Branding (Phase 0). Die vollständige Seite „Erscheinungsbild“ mit
* Logo-Varianten, Schriften, Vorschau usw. folgt in Phase 5.
*/
class Appearance extends Page
{
protected string $view = 'filament.pages.appearance';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPaintBrush;
protected static string|UnitEnum|null $navigationGroup = 'System';
protected static ?string $navigationLabel = 'Erscheinungsbild';
protected static ?string $title = 'Erscheinungsbild';
protected static ?string $slug = 'erscheinungsbild';
/** @var array<string, mixed>|null */
public ?array $data = [];
public function mount(Branding $branding): void
{
$this->form->fill([
'portal_name' => $branding->portalName(),
'primary_color' => $branding->primaryColor(),
'logo_path' => $branding->logoPath(),
]);
}
public function form(Schema $schema): Schema
{
return $schema
->components([
Section::make('Portal')
->description('Name und Logo erscheinen im Kopfbereich, auf der Anmeldeseite und im Browser-Tab.')
->schema([
TextInput::make('portal_name')
->label('Name des Portals')
->placeholder(Branding::DEFAULT_NAME)
->maxLength(60),
FileUpload::make('logo_path')
->label('Logo')
->helperText('SVG, PNG oder WebP, am besten mit transparentem Hintergrund.')
->disk('uploads')
->directory('branding')
->visibility('public')
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp'])
->maxSize(2048),
]),
Section::make('Farben')
->description('Aus der Primärfarbe wird die komplette Farbpalette für den hellen und den dunklen Modus berechnet.')
->schema([
ColorPicker::make('primary_color')
->label('Primärfarbe')
->regex('/^#[0-9a-fA-F]{6}$/')
->required(),
]),
])
->statePath('data');
}
public function save(Settings $settings, Branding $branding): void
{
$data = $this->form->getState();
$previousLogo = $branding->logoPath();
$settings->setMany([
'branding.portal_name' => filled($data['portal_name']) ? trim($data['portal_name']) : null,
'branding.primary_color' => strtoupper($data['primary_color']),
'branding.logo_path' => $data['logo_path'] ?: null,
]);
if ($previousLogo && $previousLogo !== $data['logo_path']) {
Storage::disk('uploads')->delete($previousLogo);
}
Notification::make()
->success()
->title('Erscheinungsbild gespeichert')
->send();
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource;
use Filament\Resources\Pages\CreateRecord;
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;
}

View file

@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListUsers extends ListRecords
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View file

@ -0,0 +1,63 @@
<?php
namespace App\Filament\Resources\Users\Schemas;
use App\Models\User;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Validation\Rules\Password;
class UserForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->columns(3)
->components([
Section::make('Person')
->columnSpan(2)
->columns(2)
->schema([
TextInput::make('first_name')->label('Vorname')->required()->maxLength(100),
TextInput::make('last_name')->label('Nachname')->required()->maxLength(100),
TextInput::make('email')
->label('E-Mail-Adresse')
->email()
->required()
->maxLength(255)
->unique(ignoreRecord: true)
->columnSpanFull(),
TextInput::make('job_title')->label('Funktion')->maxLength(150),
TextInput::make('department')->label('Abteilung')->maxLength(150),
TextInput::make('location')->label('Standort')->maxLength(150),
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
TextInput::make('mobile')->label('Mobil')->tel()->maxLength(50),
Textarea::make('about')->label('Über mich')->rows(3)->maxLength(2000)->columnSpanFull(),
]),
Section::make('Konto')
->columnSpan(1)
->schema([
Toggle::make('is_active')
->label('Aktiv')
->helperText('Deaktivierte Konten können sich nicht anmelden und erscheinen nicht im Portal.')
->default(true),
Toggle::make('is_admin')
->label('Administrator')
->helperText('Zugriff auf diesen Admin-Bereich. Wird später durch Rollen ersetzt.')
->disabled(fn (?User $record) => $record?->is(auth()->user()) ?? false),
TextInput::make('password')
->label(fn (string $operation) => $operation === 'create' ? 'Passwort' : 'Neues Passwort')
->helperText(fn (string $operation) => $operation === 'create'
? 'Leer lassen, wenn sich die Person nur über den Identity Provider anmelden soll.'
: 'Leer lassen, um das Passwort nicht zu ändern.')
->password()
->revealable()
->rule(Password::default())
->dehydrated(fn (?string $state) => filled($state)),
]),
]);
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace App\Filament\Resources\Users\Tables;
use App\Models\User;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
class UsersTable
{
public static function configure(Table $table): Table
{
return $table
->defaultSort('name')
->columns([
ImageColumn::make('avatar')
->label('')
->circular()
->state(fn (User $record) => $record->avatarUrl(96))
->width(40),
TextColumn::make('name')->label('Name')->searchable()->sortable(),
TextColumn::make('email')->label('E-Mail')->searchable()->toggleable(),
TextColumn::make('job_title')->label('Funktion')->toggleable(),
TextColumn::make('department')->label('Abteilung')->sortable()->toggleable(),
TextColumn::make('location')->label('Standort')->sortable()->toggleable(isToggledHiddenByDefault: true),
IconColumn::make('is_admin')->label('Admin')->boolean(),
IconColumn::make('is_active')->label('Aktiv')->boolean(),
TextColumn::make('last_login_at')
->label('Letzte Anmeldung')
->since()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
TernaryFilter::make('is_active')->label('Aktiv'),
TernaryFilter::make('is_admin')->label('Administrator'),
SelectFilter::make('department')
->label('Abteilung')
->options(fn () => User::query()->whereNotNull('department')->distinct()->orderBy('department')->pluck('department', 'department')->all()),
])
->recordActions([
EditAction::make(),
]);
}
}

View file

@ -0,0 +1,57 @@
<?php
namespace App\Filament\Resources\Users;
use App\Filament\Resources\Users\Pages\CreateUser;
use App\Filament\Resources\Users\Pages\EditUser;
use App\Filament\Resources\Users\Pages\ListUsers;
use App\Filament\Resources\Users\Schemas\UserForm;
use App\Filament\Resources\Users\Tables\UsersTable;
use App\Models\User;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
protected static ?string $modelLabel = 'Benutzer';
protected static ?string $pluralModelLabel = 'Benutzer';
protected static ?string $slug = 'benutzer';
protected static ?string $recordTitleAttribute = 'name';
public static function form(Schema $schema): Schema
{
return UserForm::configure($schema);
}
public static function table(Table $table): Table
{
return UsersTable::configure($table);
}
/**
* @return array<int, string>
*/
public static function getGloballySearchableAttributes(): array
{
return ['name', 'email', 'department'];
}
public static function getPages(): array
{
return [
'index' => ListUsers::route('/'),
'create' => CreateUser::route('/neu'),
'edit' => EditUser::route('/{record}/bearbeiten'),
];
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}

View file

@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class DashboardController extends Controller
{
public function __invoke(Request $request): Response
{
return Inertia::render('Dashboard');
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Inertia\Inertia;
use Inertia\Response;
class PeopleController extends Controller
{
public function show(User $user): Response
{
abort_unless($user->is_active, 404);
return Inertia::render('Profile/Show', [
'person' => [
'id' => $user->id,
'name' => $user->name,
'initials' => $user->initials,
'email' => $user->email,
'job_title' => $user->job_title,
'department' => $user->department,
'location' => $user->location,
'phone' => $user->phone,
'mobile' => $user->mobile,
'about' => $user->about,
'avatar_url' => $user->avatarUrl(256),
],
'isOwnProfile' => $user->is(auth()->user()),
]);
}
}

View file

@ -0,0 +1,75 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\UpdateProfileRequest;
use App\Models\User;
use App\Support\Avatars;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\File;
use Inertia\Inertia;
use Inertia\Response;
class ProfileController extends Controller
{
public function show(Request $request): RedirectResponse
{
return to_route('people.show', $request->user());
}
public function edit(Request $request): Response
{
$user = $request->user();
return Inertia::render('Profile/Edit', [
'profile' => [
...$user->only([
'first_name', 'last_name', 'email', 'job_title', 'department',
'location', 'phone', 'mobile', 'about', 'theme',
]),
'name' => $user->name,
'initials' => $user->initials,
'avatar_url' => $user->avatarUrl(256),
'has_password' => $user->password !== null,
],
]);
}
public function update(UpdateProfileRequest $request): RedirectResponse
{
$request->user()->update($request->validated());
return back()->with('status', 'profile-updated');
}
public function updateAvatar(Request $request, Avatars $avatars): RedirectResponse
{
$request->validate([
'avatar' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp'])->max(8 * 1024)],
]);
$avatars->store($request->user(), $request->file('avatar'));
return back()->with('status', 'avatar-updated');
}
public function destroyAvatar(Request $request, Avatars $avatars): RedirectResponse
{
$avatars->delete($request->user());
return back()->with('status', 'avatar-deleted');
}
public function updateTheme(Request $request): RedirectResponse
{
$validated = $request->validate([
'theme' => ['required', Rule::in(User::THEMES)],
]);
$request->user()->update($validated);
return back();
}
}

View file

@ -0,0 +1,42 @@
<?php
namespace App\Http\Middleware;
use App\Support\Branding;
use Illuminate\Http\Request;
use Inertia\Middleware;
class HandleInertiaRequests extends Middleware
{
protected $rootView = 'app';
public function __construct(private readonly Branding $branding) {}
/**
* @return array<string, mixed>
*/
public function share(Request $request): array
{
$user = $request->user();
return [
...parent::share($request),
'branding' => $this->branding->toArray(),
'auth' => [
'user' => $user ? [
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
'initials' => $user->initials,
'job_title' => $user->job_title,
'avatar_url' => $user->avatarUrl(96),
'theme' => $user->theme,
'is_admin' => $user->is_admin,
] : null,
],
'flash' => [
'status' => fn () => $request->session()->get('status'),
],
];
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateProfileRequest extends FormRequest
{
/**
* @return array<string, mixed>
*/
public function rules(): array
{
return [
'first_name' => ['required', 'string', 'max:100'],
'last_name' => ['required', 'string', 'max:100'],
'email' => [
'required', 'string', 'lowercase', 'email', 'max:255',
Rule::unique('users')->ignore($this->user()->id),
],
'job_title' => ['nullable', 'string', 'max:150'],
'department' => ['nullable', 'string', 'max:150'],
'location' => ['nullable', 'string', 'max:150'],
'phone' => ['nullable', 'string', 'max:50'],
'mobile' => ['nullable', 'string', 'max:50'],
'about' => ['nullable', 'string', 'max:2000'],
];
}
/**
* @return array<string, string>
*/
public function attributes(): array
{
return [
'first_name' => 'Vorname',
'last_name' => 'Nachname',
'email' => 'E-Mail-Adresse',
'job_title' => 'Funktion',
'department' => 'Abteilung',
'location' => 'Standort',
'phone' => 'Telefon',
'mobile' => 'Mobil',
'about' => 'Über mich',
];
}
}

23
app/Models/Setting.php Normal file
View file

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
#[Fillable(['key', 'value'])]
class Setting extends Model
{
protected $primaryKey = 'key';
protected $keyType = 'string';
public $incrementing = false;
protected function casts(): array
{
return [
'value' => 'json',
];
}
}

95
app/Models/User.php Normal file
View file

@ -0,0 +1,95 @@
<?php
namespace App\Models;
use App\Support\Avatars;
use Database\Factories\UserFactory;
use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasAvatar;
use Filament\Panel;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Str;
#[Fillable([
'name', 'first_name', 'last_name', 'email', 'password',
'job_title', 'department', 'location', 'phone', 'mobile', 'about',
'is_admin', 'is_active', 'theme',
])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable implements FilamentUser, HasAvatar
{
/** @use HasFactory<UserFactory> */
use HasFactory, Notifiable;
public const THEMES = ['system', 'light', 'dark'];
protected static function booted(): void
{
// Der Anzeigename folgt Vor- und Nachname, solange beide gepflegt sind.
static::saving(function (User $user): void {
$fullName = trim($user->first_name.' '.$user->last_name);
if ($fullName !== '') {
$user->name = $fullName;
}
});
}
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'last_login_at' => 'datetime',
'password' => 'hashed',
'is_admin' => 'boolean',
'is_active' => 'boolean',
];
}
/**
* Vorläufig: Zugriff auf das Admin-Backend über das Flag is_admin.
* Wird in Phase 2 durch das Rollen- und Rechtesystem ersetzt.
*/
public function canAccessPanel(Panel $panel): bool
{
return $this->is_admin && $this->is_active;
}
public function getFilamentAvatarUrl(): ?string
{
return $this->avatarUrl(96);
}
public function avatarUrl(int $size = 256): ?string
{
return app(Avatars::class)->url($this, $size);
}
/**
* @return Attribute<string, never>
*/
protected function initials(): Attribute
{
return Attribute::get(function (): string {
$parts = preg_split('/\s+/', trim($this->name)) ?: [];
$first = Str::substr($parts[0] ?? '', 0, 1);
$last = count($parts) > 1 ? Str::substr(end($parts), 0, 1) : '';
return Str::upper($first.$last) ?: '?';
});
}
/**
* @param Builder<User> $query
*/
public function scopeActive(Builder $query): void
{
$query->where('is_active', true);
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace App\Providers;
use App\Support\Avatars;
use App\Support\Branding;
use App\Support\Settings;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rules\Password;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(Settings::class);
$this->app->singleton(Branding::class);
$this->app->singleton(Avatars::class);
}
public function boot(): void
{
// N+1-Abfragen in Entwicklung und Tests sofort sichtbar machen (docs/PLAN.md, Performance).
Model::preventLazyLoading(! $this->app->isProduction());
Password::defaults(fn () => Password::min(10)->letters()->numbers());
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace App\Providers\Filament;
use App\Support\Branding;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\AuthenticateSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Navigation\NavigationItem;
use Filament\Pages\Dashboard;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Support\Icons\Heroicon;
use Filament\Widgets\AccountWidget;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
// Keine eigene Filament-Anmeldung: das Admin-Backend nutzt den Portal-Login
// (und damit später auch Entra ID). Nicht angemeldete Personen landen auf /login.
return $panel
->default()
->id('admin')
->path('admin')
->brandName(fn () => app(Branding::class)->portalName())
->brandLogo(fn () => app(Branding::class)->logoUrl())
->colors(fn () => [
'primary' => Color::hex(app(Branding::class)->primaryColor()),
])
->navigationItems([
NavigationItem::make('Zum Portal')
->url('/')
->icon(Heroicon::OutlinedArrowTopRightOnSquare)
->sort(100),
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
->pages([
Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
->widgets([
AccountWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
PreventRequestForgery::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
}

View file

@ -0,0 +1,65 @@
<?php
namespace App\Providers;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Models\User;
use Illuminate\Auth\Events\Login;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Inertia\Inertia;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
public function boot(): void
{
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
Fortify::loginView(fn (Request $request) => Inertia::render('Auth/Login', [
'canResetPassword' => true,
'status' => $request->session()->get('status'),
]));
Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('Auth/ForgotPassword', [
'status' => $request->session()->get('status'),
]));
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('Auth/ResetPassword', [
'email' => $request->input('email'),
'token' => $request->route('token'),
]));
// Deaktivierte Konten und Konten ohne lokales Passwort (später: nur IdP) können
// sich nicht per Passwort anmelden.
Fortify::authenticateUsing(function (Request $request): ?User {
$user = User::query()->where('email', Str::lower($request->input(Fortify::username())))->first();
if ($user && $user->is_active && $user->password !== null
&& Hash::check($request->input('password'), $user->password)) {
return $user;
}
return null;
});
Event::listen(Login::class, function (Login $event): void {
if ($event->user instanceof User) {
$event->user->forceFill(['last_login_at' => now()])->saveQuietly();
}
});
RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
return Limit::perMinute(5)->by($throttleKey);
});
}
}

64
app/Support/Avatars.php Normal file
View file

@ -0,0 +1,64 @@
<?php
namespace App\Support;
use App\Models\User;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Encoders\WebpEncoder;
use Intervention\Image\ImageManager;
/**
* Speichert Profilbilder als quadratische WebP-Dateien in festen Größen.
*
* Die Bilder liegen im öffentlichen Upload-Verzeichnis und werden von Apache
* direkt ausgeliefert – ohne PHP und ohne Symlink (auf Shared Hosting oft
* nicht möglich). Der Zufallsanteil im Dateinamen macht die URL bei jedem
* neuen Bild eindeutig, sodass sie lange gecacht werden darf.
*/
class Avatars
{
/** Pixelgrößen, die erzeugt werden (Header, Listen, Profilseite). */
public const SIZES = [96, 256];
public function store(User $user, UploadedFile $file): void
{
$image = ImageManager::usingDriver(Driver::class)->decodePath($file->getRealPath());
$base = 'avatars/'.$user->getKey().'/'.Str::random(12);
foreach (self::SIZES as $size) {
$encoded = (clone $image)->cover($size, $size)->encode(new WebpEncoder(quality: 85));
Storage::disk('uploads')->put("{$base}-{$size}.webp", $encoded->toString());
}
$this->delete($user);
$user->forceFill(['avatar_path' => $base])->save();
}
public function delete(User $user): void
{
if ($user->avatar_path === null) {
return;
}
foreach (self::SIZES as $size) {
Storage::disk('uploads')->delete("{$user->avatar_path}-{$size}.webp");
}
$user->forceFill(['avatar_path' => null])->save();
}
public function url(User $user, int $size = 256): ?string
{
if ($user->avatar_path === null) {
return null;
}
$size = in_array($size, self::SIZES, true) ? $size : max(self::SIZES);
return Storage::disk('uploads')->url("{$user->avatar_path}-{$size}.webp");
}
}

56
app/Support/Branding.php Normal file
View file

@ -0,0 +1,56 @@
<?php
namespace App\Support;
use Illuminate\Support\Facades\Storage;
/**
* Basis-Branding der Installation (Phase 0): Portalname, Logo, Primärfarbe.
* Das vollständige Erscheinungsbild folgt in Phase 5 (docs/PLAN.md, Abschnitt 12).
*/
class Branding
{
public const DEFAULT_NAME = 'Inhaus';
public const DEFAULT_PRIMARY_COLOR = '#2E6B5E';
public function __construct(private readonly Settings $settings) {}
public function portalName(): string
{
return $this->settings->get('branding.portal_name') ?: self::DEFAULT_NAME;
}
public function primaryColor(): string
{
$color = $this->settings->get('branding.primary_color');
return is_string($color) && preg_match('/^#[0-9a-fA-F]{6}$/', $color)
? strtoupper($color)
: self::DEFAULT_PRIMARY_COLOR;
}
public function logoPath(): ?string
{
return $this->settings->get('branding.logo_path') ?: null;
}
public function logoUrl(): ?string
{
$path = $this->logoPath();
return $path ? Storage::disk('uploads')->url($path) : null;
}
/**
* @return array{portal_name: string, primary_color: string, logo_url: string|null}
*/
public function toArray(): array
{
return [
'portal_name' => $this->portalName(),
'primary_color' => $this->primaryColor(),
'logo_url' => $this->logoUrl(),
];
}
}

62
app/Support/Settings.php Normal file
View file

@ -0,0 +1,62 @@
<?php
namespace App\Support;
use App\Models\Setting;
use Illuminate\Support\Facades\Cache;
/**
* Systemweite Einstellungen als Schlüssel/Wert-Paare.
*
* Alle Werte werden gemeinsam gecacht, damit ein Seitenaufruf höchstens eine
* Abfrage braucht – egal wie viele Einstellungen gelesen werden.
*/
class Settings
{
private const CACHE_KEY = 'settings.all';
/** @var array<string, mixed>|null */
private ?array $values = null;
public function get(string $key, mixed $default = null): mixed
{
return $this->all()[$key] ?? $default;
}
public function set(string $key, mixed $value): void
{
Setting::query()->updateOrCreate(['key' => $key], ['value' => $value]);
$this->flush();
}
/**
* @param array<string, mixed> $values
*/
public function setMany(array $values): void
{
foreach ($values as $key => $value) {
Setting::query()->updateOrCreate(['key' => $key], ['value' => $value]);
}
$this->flush();
}
/**
* @return array<string, mixed>
*/
public function all(): array
{
return $this->values ??= Cache::rememberForever(
self::CACHE_KEY,
fn () => Setting::query()->pluck('value', 'key')->all(),
);
}
public function flush(): void
{
$this->values = null;
Cache::forget(self::CACHE_KEY);
}
}

13
app/Version.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace App;
/**
* Release-Version des Codes (SemVer). Bei jeder Änderung zusammen mit
* CHANGELOG.md anheben – siehe CONTRIBUTING.md. Den installierten
* Commit-Stand verwaltet der Self-Updater getrennt davon.
*/
final class Version
{
public const VERSION = '0.1.0';
}