SinglePageController.php 3.3 KB

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