v0.9.3
This commit is contained in:
commit
22f164046e
286 files changed
+19176
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use IriksIT\Manager\Support\Names;
|
||||
use IriksIT\Manager\Support\TwoFactor\Authenticator;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* The gate of the second step (ADR-0016). After the login, whichever login that was, an account that has a second step but has not passed it in this session
|
||||
* reaches nothing of the manager but the answer to the challenge and logging out; an account that has to have one, has none and is out of
|
||||
* its grace period reaches nothing but setting it up and logging out. Everything else answers `423 Locked` with the reason, and a browser that is not
|
||||
* asking for data goes to the manager, where the screen shows what to do.
|
||||
*/
|
||||
class RequireTwoFactor
|
||||
{
|
||||
/** What may be reached in each state, by route name without the prefix. */
|
||||
private const ALLOWED = [
|
||||
'challenge' => ['two_factor.status', 'two_factor.challenge', 'logout'],
|
||||
'setup_required' => ['two_factor.status', 'two_factor.setup', 'two_factor.confirm', 'logout'],
|
||||
];
|
||||
|
||||
public function __construct(private readonly Authenticator $authenticator) {}
|
||||
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if ($user === null) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$state = $this->authenticator->state($user)['state'];
|
||||
|
||||
if (! isset(self::ALLOWED[$state])) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$name = (string) $request->route()?->getName();
|
||||
$prefix = Names::routePrefix();
|
||||
|
||||
if (str_starts_with($name, $prefix) && in_array(substr($name, strlen($prefix)), self::ALLOWED[$state], true)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($request->expectsJson() || $request->ajax()) {
|
||||
return response()->json(['message' => __('A second step is needed first.'), 'two_factor' => $state], 423);
|
||||
}
|
||||
|
||||
return redirect('/'.trim((string) config('manager.path'), '/'));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user