Correzioni per retro-compatibilità API

This commit is contained in:
Dasc3er 2021-02-19 16:15:50 +01:00
parent 2f2e59e325
commit c1b3b1f118
4 changed files with 26 additions and 9 deletions

View File

@ -50,7 +50,10 @@ class InfoController extends Controller
public function user()
{
$token = auth()->getToken();
$user = auth()->user();
$tokens = $user->getApiTokens();
$token = $tokens[0]['token'];
$api = BASEURL.'/api/?token='.$token;

View File

@ -5,19 +5,30 @@ namespace App\Http\Controllers;
use App\Exceptions\LegacyExitException;
use App\Exceptions\LegacyRedirectException;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class LegacyController extends Controller
{
public function index($path = 'index.php')
public function index(Request $request, $path = 'index.php')
{
$base_path = base_path('legacy');
// Fix per redirect all'API
$api_request = false;
if (in_array($path, ['api', 'api/', 'api/index.php'])) {
$path = 'api/index.php';
$api_request = true;
}
// Ricerca del file interessato
$file = realpath($base_path.'/'.$path);
if (strpos($file, $base_path) === false) {
throw new NotFoundHttpException();
}
// Inclusione diretta del file
ob_start();
try {
require $file;
@ -26,13 +37,17 @@ class LegacyController extends Controller
return Redirect::to($e->getMessage());
}
// Gestione dell'output
$output = ob_get_clean();
$response = response($output);
// Fix content-type per contenuti non HTML
if (ends_with($path, '.js')) {
$response = $response->header('Content-Type', 'application/javascript');
} elseif (string_contains($path, 'pdfgen.php')) {
$response = $response->header('Content-Type', 'application/pdf');
} elseif ($api_request) {
$response = $response->header('Content-Type', 'application/json');
}
return $response;

View File

@ -42,14 +42,13 @@
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5",
"league/csv": "^8.2",
"mpdf/mpdf": "^v8.0.7",
"mpdf/mpdf": "^8.0.10",
"mpociot/vat-calculator": "^2.3",
"nwidart/laravel-modules": "^8.2",
"owasp/csrf-protector-php": "^1.0",
"phpmailer/phpmailer": "^6.0",
"respect/validation": "^1.1",
"servo/fluidxml": "^1.21",
"spipu/html2pdf": "^5.0",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-php70": "^1.8",
"willdurand/geocoder": "^3.3",

View File

@ -16,6 +16,10 @@ Route::get('/login', [AuthenticatedSessionController::class, 'create'])
Route::post('/login', [AuthenticatedSessionController::class, 'store'])
->middleware('guest');
Route::get('/logout', [AuthenticatedSessionController::class, 'destroy'])
->middleware('auth')
->name('logout');
Route::get('/forgot-password', [PasswordResetLinkController::class, 'create'])
->middleware('guest')
->name('password.request');
@ -50,7 +54,3 @@ Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show'])
Route::post('/confirm-password', [ConfirmablePasswordController::class, 'store'])
->middleware('auth');
Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])
->middleware('auth')
->name('logout');