SinglePageController.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Events\ScanForNewReleaseCalled;
  4. use App\Facades\Settings;
  5. use Illuminate\Support\Facades\App;
  6. use Illuminate\Support\Facades\Vite;
  7. class SinglePageController extends Controller
  8. {
  9. /**
  10. * return the main view
  11. *
  12. * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
  13. */
  14. public function index()
  15. {
  16. $appSettings = Settings::all();
  17. if ($appSettings['checkForUpdate'] == true) {
  18. event(new ScanForNewReleaseCalled);
  19. }
  20. // We only share necessary and acceptable values with the HTML front-end.
  21. // But all the properties have to be pushed to init the appSetting store state correctly,
  22. // so we set them to null, they will be fed later by the front-end
  23. $publicSettings = $appSettings->only([
  24. 'disableRegistration',
  25. 'enableSso',
  26. 'useSsoOnly',
  27. ]);
  28. $settings = $appSettings->map(function (mixed $item, string $key) {
  29. return null;
  30. })->merge($publicSettings)->toJson();
  31. $proxyAuth = config('auth.defaults.guard') === 'reverse-proxy-guard' ? true : false;
  32. $proxyLogoutUrl = config('2fauth.config.proxyLogoutUrl') ? config('2fauth.config.proxyLogoutUrl') : false;
  33. $subdir = config('2fauth.config.appSubdirectory') ? '/' . config('2fauth.config.appSubdirectory') : '';
  34. $defaultPreferences = collect(config('2fauth.preferences')); /** @phpstan-ignore-line */
  35. $lockedPreferences = collect(config('2fauth.lockedPreferences')); /** @phpstan-ignore-line */
  36. $isDemoApp = config('2fauth.config.isDemoApp') ? 'true' : 'false';
  37. $isTestingApp = config('2fauth.config.isTestingApp') ? 'true' : 'false';
  38. $lang = App::getLocale();
  39. $locales = collect(config('2fauth.locales'))->toJson(); /** @phpstan-ignore-line */
  40. $openidAuth = config('services.openid.client_secret') ? true : false;
  41. $githubAuth = config('services.github.client_secret') ? true : false;
  42. $installDocUrl = config('2fauth.installDocUrl');
  43. $ssoDocUrl = config('2fauth.ssoDocUrl');
  44. $exportSchemaUrl = config('2fauth.exportSchemaUrl');
  45. $isSecure = str_starts_with(config('app.url'), 'https');
  46. $viewData = [
  47. 'appSettings' => $settings,
  48. 'appConfig' => collect([
  49. 'proxyAuth' => $proxyAuth,
  50. 'proxyLogoutUrl' => $proxyLogoutUrl,
  51. 'sso' => [
  52. 'openid' => $openidAuth,
  53. 'github' => $githubAuth,
  54. ],
  55. 'subdirectory' => $subdir,
  56. ])->toJson(),
  57. 'urls' => collect([
  58. 'installDocUrl' => $installDocUrl,
  59. 'ssoDocUrl' => $ssoDocUrl,
  60. 'exportSchemaUrl' => $exportSchemaUrl,
  61. ]),
  62. 'defaultPreferences' => $defaultPreferences,
  63. 'lockedPreferences' => $lockedPreferences,
  64. 'subdirectory' => $subdir,
  65. 'isDemoApp' => $isDemoApp,
  66. 'isTestingApp' => $isTestingApp,
  67. 'lang' => $lang,
  68. 'locales' => $locales,
  69. 'isSecure' => $isSecure,
  70. ];
  71. if (config('2fauth.config.contentSecurityPolicy')) {
  72. $viewData['cspNonce'] = Vite::cspNonce();
  73. }
  74. return view('landing')->with($viewData);
  75. }
  76. }