diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9452827..e2bd13c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,11 @@ -image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0 - stages: - Security - CodingStandards + - Builds composer-security: stage: Security + image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0 script: - local-php-security-checker --format=json --path=./composer.lock > composer-security-checker-report.json artifacts: @@ -14,9 +14,13 @@ composer-security: paths: - composer-security-checker-report.json allow_failure: true + needs: [] npm-security: stage: Security + image: node:17.9.1 + before_script: + - npm install --location=global audit-ci@^6 script: - audit-ci -p npm -o json > npm-security-checker-report.json artifacts: @@ -25,9 +29,11 @@ npm-security: paths: - npm-security-checker-report.json allow_failure: true + needs: [] phpcs: stage: CodingStandards + image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0 before_script: - composer config gitlab-token.gitlab.com $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD - composer install @@ -44,3 +50,25 @@ phpcs: reports: junit: phpcs-report.xml allow_failure: false + needs: + - composer-security + - npm-security + +front-build: + stage: Builds + image: node:17.9.1 + before_script: + - npm install + cache: + paths: + - node_modules/ + script: + - npm run prod > front-build-report.json + artifacts: + when: on_failure + expose_as: 'front-build-report' + paths: + - front-build-report.json + allow_failure: false + needs: + - phpcs diff --git a/app/Http/Middleware/LangCheck.php b/app/Http/Middleware/LangCheck.php index 0fa7bd6..11ca98c 100644 --- a/app/Http/Middleware/LangCheck.php +++ b/app/Http/Middleware/LangCheck.php @@ -5,17 +5,11 @@ namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cookie; +use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\View; class LangCheck { - /** - * The available languages. - * - * @var array - */ - protected $langs = ['fr','en','es']; - /** * Handle an incoming request. * @@ -27,6 +21,8 @@ class LangCheck { $routName = $request->route()->getName(); + + $routeParams = Route::current()->parameters(); if (preg_match('/^bo\./', $routName)) { // Back office. if ($request->lang) { @@ -39,10 +35,9 @@ class LangCheck } } else { // FRONT. - if (preg_match('/^(en|es)\./', $routName)) { + if (preg_match('/^(' . \implode("|", config('app.other_locales')) . ')\./', $routName)) { // From front use named routes. $langset = $request->segment(1); - $this->saveUserLocale($langset, $request); } else { // Not specified in route. @@ -52,25 +47,24 @@ class LangCheck $sess_lang = $request->session()->get('lang', config('app.locale')); switch ($sess_lang) { case 'en': - return redirect()->route($routNameEN); + return redirect()->route($routNameEN, $routeParams); case 'es': - return redirect()->route($routNameES); + return redirect()->route($routNameES, $routeParams); } } $langset = 'fr'; $this->saveUserLocale($langset, $request); - }//end if + } //end if }//end if - $sess_lang = $request->session()->get('lang', config('app.locale')); app()->setLocale($sess_lang); config(['app.locale' => $sess_lang]); $routePrefixer = ""; - if ($sess_lang != 'fr') { + if ($sess_lang != config('app.locale')) { $routePrefixer = $sess_lang . '.'; } View::share('routeprefixer', $routePrefixer); @@ -109,9 +103,9 @@ class LangCheck if (is_null($fromC) || empty($fromC)) { // Pas de cookie, recherche sur le navigateur. $fromC = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2); - if (!in_array($fromC, $this->langs)) { - // Default other languages to en. - $fromC = 'en'; + if (!in_array($fromC, config('app.other_locales'))) { + // Default other languages to config('app.locale'). + $fromC = config('app.locale'); } } $this->saveUserLocale($fromC, $request); diff --git a/config/app.php b/config/app.php index 08fee42..1666cc8 100644 --- a/config/app.php +++ b/config/app.php @@ -108,6 +108,13 @@ return [ 'faker_locale' => 'fr_FR', + /** + * All locales + */ + + 'other_locales' => ['en', 'es'], + + /* |-------------------------------------------------------------------------- | Encryption Key diff --git a/config/refresh-sitemap.php b/config/refresh-sitemap.php index caf04ef..14b20fd 100644 --- a/config/refresh-sitemap.php +++ b/config/refresh-sitemap.php @@ -16,9 +16,7 @@ return [ * just add '/backoffice' into this table */ 'ignoreRoutes' => [ - '/bo', - '/en', - '/es' + '/bo' ], /** diff --git a/resources/views/layouts/frontend/app-header.blade.php b/resources/views/layouts/frontend/app-header.blade.php index 6039ea0..59584b7 100644 --- a/resources/views/layouts/frontend/app-header.blade.php +++ b/resources/views/layouts/frontend/app-header.blade.php @@ -99,13 +99,11 @@ - @if (config('app.env') != 'production') - @endif
@@ -129,8 +127,8 @@ -@endpush +@endpush \ No newline at end of file