From 9fd4b56066b28b30a2c87d7edb823d1868a77a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Tue, 23 Jan 2024 16:05:47 +0000 Subject: [PATCH] Fix FLEXIAPI-136 Refactor the Web Panel toggle mechanism and move it to a proper Middleware --- CHANGELOG.md | 11 +++++ flexiapi/app/Helpers/Utils.php | 5 --- flexiapi/app/Http/Kernel.php | 1 + flexiapi/app/Http/Middleware/Authenticate.php | 2 +- .../app/Http/Middleware/IsWebPanelEnabled.php | 42 +++++++++++++++++++ .../resources/views/account/login.blade.php | 2 +- .../resources/views/layouts/main.blade.php | 40 +++++++++--------- .../resources/views/parts/recovery.blade.php | 30 +++++++------ flexiapi/routes/web.php | 30 ++++++------- 9 files changed, 104 insertions(+), 59 deletions(-) create mode 100644 flexiapi/app/Http/Middleware/IsWebPanelEnabled.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ec1ce34..4ff6883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ v1.5 ---- +- Fix FLEXIAPI-136 Refactor the Web Panel toggle mechanism and move it to a proper Middleware +- Fix FLEXIAPI-133 Use the correct breadcrumb on create and fix a password +- Fix #143 Ensure that the ProvisioningToken model behave likes all the other Consommable - Fix #141 Add a new hook system for the Account Service - Fix #138 Add a dictionary attached to the accounts - Fix #137 Migrate the icons from Material Icons to Material Symbols @@ -11,6 +14,14 @@ v1.5 - Fix #132 Move the provisioning_tokens and recovery_codes to dedicated table - Fix #130 Drop the group column in the Accounts table +v1.4.4 +------ +- Fix FLEXIAPI-136 Refactor the Web Panel toggle mechanism and move it to a proper Middleware + +v1.4.3 +------ +- Fix FLEXIAPI-133 Use the correct breadcrumb on create and fix a password update related issue on update + v1.4.2 ------ - Fix #135 Refactor the password algorithms code diff --git a/flexiapi/app/Helpers/Utils.php b/flexiapi/app/Helpers/Utils.php index 20cece1..4249a8d 100644 --- a/flexiapi/app/Helpers/Utils.php +++ b/flexiapi/app/Helpers/Utils.php @@ -92,11 +92,6 @@ function markdownDocumentationView($view): string ); } -function publicRegistrationEnabled(): bool -{ - return (config('app.public_registration')); -} - function isRegularExpression($string): bool { set_error_handler(function () { diff --git a/flexiapi/app/Http/Kernel.php b/flexiapi/app/Http/Kernel.php index 9790a8f..d7a3602 100644 --- a/flexiapi/app/Http/Kernel.php +++ b/flexiapi/app/Http/Kernel.php @@ -72,6 +72,7 @@ class Kernel extends HttpKernel 'auth.admin' => \App\Http\Middleware\AuthenticateAdmin::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.digest_or_key' => \App\Http\Middleware\AuthenticateDigestOrKey::class, + 'web_panel_enabled' => \App\Http\Middleware\IsWebPanelEnabled::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, diff --git a/flexiapi/app/Http/Middleware/Authenticate.php b/flexiapi/app/Http/Middleware/Authenticate.php index 18ed0ec..6fb8764 100644 --- a/flexiapi/app/Http/Middleware/Authenticate.php +++ b/flexiapi/app/Http/Middleware/Authenticate.php @@ -14,7 +14,7 @@ class Authenticate extends Middleware */ protected function redirectTo($request) { - if (! $request->expectsJson()) { + if (!$request->expectsJson()) { return route('account.home'); } } diff --git a/flexiapi/app/Http/Middleware/IsWebPanelEnabled.php b/flexiapi/app/Http/Middleware/IsWebPanelEnabled.php new file mode 100644 index 0000000..156b191 --- /dev/null +++ b/flexiapi/app/Http/Middleware/IsWebPanelEnabled.php @@ -0,0 +1,42 @@ +. +*/ + +namespace App\Http\Middleware; + +use Closure; +use Illuminate\Http\Request; + +class IsWebPanelEnabled +{ + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next + * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse + */ + public function handle(Request $request, Closure $next) + { + if (!$request->expectsJson() && config('app.web_panel')) { + return $next($request); + } + + return redirect()->route('about'); + } +} diff --git a/flexiapi/resources/views/account/login.blade.php b/flexiapi/resources/views/account/login.blade.php index 0014325..56bd01c 100644 --- a/flexiapi/resources/views/account/login.blade.php +++ b/flexiapi/resources/views/account/login.blade.php @@ -37,7 +37,7 @@ @include('parts.recovery') - @if (publicRegistrationEnabled()) + @if (config('app.public_registration'))

diff --git a/flexiapi/resources/views/layouts/main.blade.php b/flexiapi/resources/views/layouts/main.blade.php index 511a932..ca1312a 100644 --- a/flexiapi/resources/views/layouts/main.blade.php +++ b/flexiapi/resources/views/layouts/main.blade.php @@ -20,30 +20,28 @@
- @if (config('app.web_panel')) -
diff --git a/flexiapi/resources/views/parts/recovery.blade.php b/flexiapi/resources/views/parts/recovery.blade.php index 15ad061..8b63573 100644 --- a/flexiapi/resources/views/parts/recovery.blade.php +++ b/flexiapi/resources/views/parts/recovery.blade.php @@ -1,16 +1,14 @@ -@if (config('app.web_panel')) -

- @if (config('app.account_email_unique')) - Set or recover your account - @else - Set or recover your password - @endif - using your Email address - @if (config('app.phone_authentication')) - or your Phone number - @endif -

-

- …or login using an already authenticated device by flashing a QRcode. -

-@endif \ No newline at end of file +

+ @if (config('app.account_email_unique')) + Set or recover your account + @else + Set or recover your password + @endif + using your Email address + @if (config('app.phone_authentication')) + or your Phone number + @endif +

+

+ …or login using an already authenticated device by flashing a QRcode. +

\ No newline at end of file diff --git a/flexiapi/routes/web.php b/flexiapi/routes/web.php index 9771e06..276040d 100644 --- a/flexiapi/routes/web.php +++ b/flexiapi/routes/web.php @@ -44,15 +44,15 @@ Route::redirect('/', 'login')->name('account.home'); Route::get('documentation', 'Account\AccountController@documentation')->name('account.documentation'); Route::get('about', 'AboutController@about')->name('about'); -if (config('app.web_panel')) { +Route::middleware(['web_panel_enabled'])->group(function () { Route::get('login', 'Account\AuthenticateController@login')->name('account.login'); Route::post('authenticate', 'Account\AuthenticateController@authenticate')->name('account.authenticate'); Route::get('authenticate/qrcode/{token?}', 'Account\AuthenticateController@loginAuthToken')->name('account.authenticate.auth_token'); -} -Route::prefix('creation_token')->controller(CreationRequestTokenController::class)->group(function () { - Route::get('check/{token}', 'check')->name('account.creation_request_token.check'); - Route::post('validate', 'validateToken')->name('account.creation_request_token.validate'); + Route::prefix('creation_token')->controller(CreationRequestTokenController::class)->group(function () { + Route::get('check/{token}', 'check')->name('account.creation_request_token.check'); + Route::post('validate', 'validateToken')->name('account.creation_request_token.validate'); + }); }); Route::group(['middleware' => 'auth.digest_or_key'], function () { @@ -71,18 +71,18 @@ Route::name('provisioning.')->prefix('provisioning')->controller(ProvisioningCon Route::get('/', 'show')->name('show'); }); -if (publicRegistrationEnabled()) { - Route::redirect('register', 'register/email')->name('account.register'); +Route::middleware(['web_panel_enabled'])->group(function () { + if (config('app.public_registration')) { + Route::redirect('register', 'register/email')->name('account.register'); - if (config('app.phone_authentication')) { - Route::get('register/phone', 'Account\RegisterController@registerPhone')->name('account.register.phone'); + if (config('app.phone_authentication')) { + Route::get('register/phone', 'Account\RegisterController@registerPhone')->name('account.register.phone'); + } + + Route::get('register/email', 'Account\RegisterController@registerEmail')->name('account.register.email'); + Route::post('accounts', 'Account\AccountController@store')->name('account.store'); } - Route::get('register/email', 'Account\RegisterController@registerEmail')->name('account.register.email'); - Route::post('accounts', 'Account\AccountController@store')->name('account.store'); -} - -if (config('app.web_panel')) { Route::prefix('recovery')->controller(RecoveryController::class)->group(function () { Route::get('phone', 'showPhone')->name('account.recovery.show.phone'); Route::get('email', 'showEmail')->name('account.recovery.show.email'); @@ -250,4 +250,4 @@ if (config('app.web_panel')) { }); }); }); -} +});