This commit is contained in:
deploy-bot committed 2026-12-04 16:24:51 +00:00
commit 8f8513f802
278 files changed
+18400

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
<?php
namespace IriksIT\Manager\Http\Controllers;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
/** The built screens, served by the package itself: the app does not need Node, a build step or a publish. */
class AssetController
{
private const FILES = ['manager.js' => 'application/javascript', 'manager.css' => 'text/css', 'vue.js' => 'application/javascript'];
public function __invoke(string $file): BinaryFileResponse
{
abort_unless(isset(self::FILES[$file]) && is_file($path = __DIR__.'/../../../resources/dist/'.$file), 404);
return response()->file($path, [
'Content-Type' => self::FILES[$file],
'Cache-Control' => 'public, max-age=31536000, immutable',
'X-Content-Type-Options' => 'nosniff',
]);
}
}
@@ -0,0 +1,39 @@
<?php
namespace IriksIT\Manager\Http\Controllers;
use Illuminate\Http\Request;
use IriksIT\Manager\Support\Menu;
use IriksIT\Manager\Support\ModuleRegistry;
use IriksIT\Manager\Support\Tiles;
class DashboardController
{
public function __invoke(Request $request, ModuleRegistry $modules, Menu $menu, Tiles $tiles)
{
$user = $request->user();
// Only what this account may reach, in the face it looks at.
$navigation = $menu->for($user, array_values(array_filter($modules->permissionValues(), fn (string $permission) => $user?->can($permission))));
// What the big buttons of the simple start screen say: by the address of the menu item.
$facts = [];
foreach ($tiles->for($user) as $route => $fact) {
$facts[route($route, [], false)] = $fact;
}
$help = (array) config('manager.simple.help', []);
$site = config('manager.simple.site_link', '/');
return $request->wantsJson()
? response()->json([
'navigation' => $navigation,
'facts' => (object) $facts,
// A way to ask for help (a name and a link, for example a WhatsApp link) and a link to the site, under the buttons.
'help' => is_string($help['link'] ?? null) && ($help['link'] ?? '') !== '' ? ['name' => (string) ($help['name'] ?? ''), 'link' => $help['link']] : null,
'site' => is_string($site) && $site !== '' ? $site : null,
])
: view('manager::dashboard', ['navigation' => $navigation]);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
namespace IriksIT\Manager\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Illuminate\Validation\ValidationException;
use IriksIT\Manager\Support\LoginChecks;
use IriksIT\Manager\Support\Names;
/** The manager's own login, for an app that has none. Failed attempts reach the audit log through Laravel's `Failed` event. */
class LoginController
{
public function store(Request $request, LoginChecks $checks): JsonResponse
{
$checks->before($request);
$credentials = $request->validate([
'email' => ['required', 'string', 'email', 'max:255'],
'password' => ['required', 'string', 'max:200'],
]);
$refused = null;
// `attemptWhen` runs the second checks after the password is right and before the login begins; a refusal is a failed login.
$loggedIn = Auth::attemptWhen($credentials, function ($user) use ($checks, $request, &$refused) {
try {
$checks->after($request, $user);
} catch (ValidationException $e) {
$refused = $e;
return false;
}
return true;
}, $request->boolean('remember'));
if (! $loggedIn) {
throw $refused ?? ValidationException::withMessages(['email' => trans('auth.failed')]);
}
$request->session()->regenerate();
return response()->json(['redirect' => '/'.trim((string) config('manager.path'), '/')]);
}
public function destroy(Request $request): JsonResponse
{
Auth::guard()->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return response()->json(['redirect' => Route::has(Names::route('login')) ? route(Names::route('login'), [], false) : '/']);
}
}
@@ -0,0 +1,18 @@
<?php
namespace IriksIT\Manager\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use IriksIT\Manager\Support\Markdown;
/** The preview of the editor: the text as the site renders it (raw HTML is escaped there, so the answer is safe to show). */
class MarkdownController
{
public function __invoke(Request $request): JsonResponse
{
$data = $request->validate(['text' => ['nullable', 'string', 'max:200000']]);
return response()->json(['html' => Markdown::toHtml((string) ($data['text'] ?? ''))]);
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace IriksIT\Manager\Http\Controllers;
use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
/**
* The pictures of the tour. A picture is `<name>.webp` or `<name>.png` in `manager.mascot.path` (default: resources/mascot of
* the package); a site can give its own set by pointing the path at a folder of its own. A picture that is not there is
* answered with a small paw, so the tour works before the pictures do.
*/
class MascotController
{
/** What the tour asks for. */
public const NAMES = ['welcome', 'point', 'calm', 'write', 'photos', 'pages', 'undo', 'oops', 'party', 'profile', 'peek'];
private const TYPES = ['webp' => 'image/webp', 'png' => 'image/png'];
public function __invoke(string $name): BinaryFileResponse|Response
{
abort_unless(in_array($name, self::NAMES, true), 404);
$folder = rtrim((string) (config('manager.mascot.path') ?: __DIR__.'/../../../resources/mascot'), '/');
foreach (self::TYPES as $extension => $type) {
if (is_file($path = "$folder/$name.$extension")) {
return response()->file($path, ['Content-Type' => $type, 'Cache-Control' => 'public, max-age=86400', 'X-Content-Type-Options' => 'nosniff']);
}
}
return response(self::paw(), 200, ['Content-Type' => 'image/svg+xml', 'Cache-Control' => 'public, max-age=300', 'X-Content-Type-Options' => 'nosniff']);
}
/** A paw: the stand-in for every picture that is not there yet. */
private static function paw(): string
{
return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><g fill="#f43f7a">'
.'<ellipse cx="64" cy="84" rx="26" ry="22"/><ellipse cx="26" cy="58" rx="11" ry="15" transform="rotate(-20 26 58)"/>'
.'<ellipse cx="50" cy="38" rx="11" ry="15" transform="rotate(-8 50 38)"/><ellipse cx="78" cy="38" rx="11" ry="15" transform="rotate(8 78 38)"/>'
.'<ellipse cx="102" cy="58" rx="11" ry="15" transform="rotate(20 102 58)"/></g></svg>';
}
}
@@ -0,0 +1,87 @@
<?php
namespace IriksIT\Manager\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rule;
use IriksIT\Manager\Models\UserSetting;
use IriksIT\Manager\Support\AuditTrail;
use IriksIT\Manager\Support\Menu;
use IriksIT\Manager\Support\Themes;
/** Your own name, password and look. Never the rights: those are the groups'. */
class ProfileController
{
public function show(Request $request, Themes $themes): JsonResponse
{
$user = $request->user();
return response()->json(['profile' => [
'name' => (string) $user->name,
'email' => (string) $user->email,
'is_super_admin' => method_exists($user, 'isManagerSuperAdmin') && $user->isManagerSuperAdmin(),
'groups' => method_exists($user, 'managerGroups') ? $user->managerGroups()->pluck('name')->values() : [],
'theme' => $themes->keyFor($user),
'locale' => UserSetting::value($user, 'locale') ?? app()->getLocale(),
'locales' => UserSetting::LOCALES,
'tutorial' => UserSetting::value($user, 'tutorial'),
'themes' => config('manager.user_themes')
? collect($themes->all())->map(fn (array $theme, string $key) => ['key' => $key, 'label' => __($theme['label']), 'colors' => $theme['colors']])->values()
: [],
]]);
}
/** The face of the manager (`full` or `simple`) an account that may switch looks at. */
public function view(Request $request, Menu $menu): JsonResponse
{
abort_unless($menu->maySwitch($request->user()), 403);
$data = $request->validate(['view' => ['required', Rule::in([Menu::FULL, Menu::SIMPLE])]]);
UserSetting::put($request->user(), ['view' => $data['view']]);
return response()->json(['view' => $data['view']]);
}
/** Where the account stands with the tour: finished, skipped, or (to look at it again) pending. Any account may, for itself. */
public function tutorial(Request $request): JsonResponse
{
$data = $request->validate(['state' => ['required', Rule::in(UserSetting::TUTORIAL)]]);
UserSetting::put($request->user(), ['tutorial' => $data['state']]);
return response()->json(['tutorial' => $data['state']]);
}
public function update(Request $request, Themes $themes): JsonResponse
{
$user = $request->user();
app(AuditTrail::class)->about($user);
$data = $request->validate([
'name' => ['required', 'string', 'max:255'],
'current_password' => ['nullable', 'string', 'max:200'],
'password' => ['nullable', 'string', 'min:12', 'max:200', 'confirmed'],
'theme' => ['nullable', 'string', Rule::in(array_keys($themes->all()))],
'locale' => ['nullable', 'string', Rule::in(UserSetting::LOCALES)],
]);
if (($data['password'] ?? '') !== '' && ! Hash::check((string) ($data['current_password'] ?? ''), $user->getAuthPassword())) {
return response()->json(['message' => $wrong = __('The current password is not right.'), 'errors' => ['current_password' => [$wrong]]], 422);
}
$user->name = $data['name'];
($data['password'] ?? '') !== '' && $user->password = Hash::make($data['password']);
$user->save();
if (config('manager.user_themes') && $request->has('theme')) {
UserSetting::put($user, ['theme' => $data['theme'] ?: null]);
}
if ($request->has('locale')) {
UserSetting::put($user, ['locale' => $data['locale'] ?: null]);
}
return response()->json(['saved' => true]);
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace IriksIT\Manager\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use IriksIT\Manager\Support\Names;
/** `auth`, but a visitor goes to the login of the host app when it has one and to the manager's own login when not. */
class Authenticate extends Middleware
{
protected function redirectTo(Request $request): ?string
{
if ($request->expectsJson()) {
return null;
}
return Route::has('login') ? route('login') : (Route::has(Names::route('login')) ? route(Names::route('login')) : null);
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace IriksIT\Manager\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use IriksIT\Manager\Support\Features;
use Symfony\Component\HttpFoundation\Response;
/** A public route of a feature: `->middleware('manager.feature:services')`. When the feature is off the page is not there. */
final class RequireFeature
{
public function handle(Request $request, Closure $next, string $feature): Response
{
abort_unless(Features::on($feature), 404);
return $next($request);
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace IriksIT\Manager\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use IriksIT\Manager\Support\Names;
use IriksIT\Manager\Support\Shell;
use Symfony\Component\HttpFoundation\Response;
/**
* The screens are one page that asks the JSON routes for its data. A browser that opens a manager address gets that
* page; the page itself, and anything else that asks for JSON, gets the data. Downloads (route names `*.export`), the
* two steps of a connection with another service (`*.connect` sends the browser away, `*.callback` is where it comes back), the
* built files and the pictures of the tour are left alone.
*/
class ServeShell
{
public function handle(Request $request, Closure $next): Response
{
if (config('manager.ui') !== 'package' || ! $request->isMethodSafe() || $request->wantsJson() || $request->ajax()) {
return $next($request);
}
$name = (string) $request->route()?->getName();
if (in_array($name, [Names::route('assets'), Names::route('mascot')], true) || str_ends_with($name, '.export') || str_ends_with($name, '.connect') || str_ends_with($name, '.callback')) {
return $next($request);
}
return response()->view('manager::shell', app(Shell::class)->data($request));
}
}
+26
View File
@@ -0,0 +1,26 @@
<?php
namespace IriksIT\Manager\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use IriksIT\Manager\Models\UserSetting;
use Symfony\Component\HttpFoundation\Response;
/**
* The language an account chose applies to everything the manager says to it (menu, messages, the shell), inside the
* manager's routes only: the site's own pages keep the language of the site. Nothing chosen: the language of the app.
*/
class SetLocale
{
public function handle(Request $request, Closure $next): Response
{
$chosen = UserSetting::value($request->user(), 'locale');
if (in_array($chosen, UserSetting::LOCALES, true)) {
app()->setLocale($chosen);
}
return $next($request);
}
}