Prechádzať zdrojové kódy

Merge branch 'hotfix/V8-5655-lien-vers-la-mise--jour-des-mots' into develop

Olivier Massot 1 rok pred
rodič
commit
38d837116a

+ 13 - 0
ot_connect/Classes/Service/OtAuthenticationService.php

@@ -9,6 +9,9 @@ use GuzzleHttp\Exception\RequestException;
 use Opentalent\OtCore\Exception\ApiRequestException;
 use Opentalent\OtCore\Logging\OtLogger;
 use Opentalent\OtCore\Service\OpentalentApiService;
+use Opentalent\OtCore\Service\OpentalentEnvService;
+use Opentalent\OtCore\Utility\NavigationUtils;
+use Opentalent\OtCore\Utility\UrlUtils;
 use TYPO3\CMS\Core\Crypto\Random;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryHelper;
@@ -235,6 +238,16 @@ class OtAuthenticationService extends AbstractAuthenticationService
                 return false;
             }
 
+            $data = json_decode((string)$response->getBody(), true);
+
+            # Redirect the user if the password needs to be changed
+            if (isset($data['type']) && $data['type'] === 'change_password') {
+                $redirectTo = UrlUtils::join(
+                    OpentalentEnvService::get('ADMIN_BASE_URL'), "/#/account/", $data['organization'], "/secure/password/", $data['token']
+                );
+                NavigationUtils::redirect($redirectTo);
+            }
+
             // The API accepted the login request
 
             // Set the cookies returned by the Api  (SESSID and BEARER)

+ 12 - 0
ot_core/Classes/Utility/NavigationUtils.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace Opentalent\OtCore\Utility;
+
+class NavigationUtils
+{
+    public static function redirect(string $url): void
+    {
+        echo "<body onload=\"window.location.replace('".$url."')\">";
+        die;
+    }
+}

+ 0 - 14
ot_core/Classes/Utility/RouteNormalizer.php

@@ -1,14 +0,0 @@
-<?php
-
-namespace Opentalent\OtCore\Utility;
-
-class RouteNormalizer
-{
-    public static function normalizePath(string $path) {
-        return '/' . trim($path, '/');
-    }
-
-    public static function normalizeDomain(string $domain) {
-        return preg_replace('/https?:\/\/([\w\.]+)(?:\/.*)?/', '$1', $domain);
-    }
-}

+ 101 - 0
ot_core/Classes/Utility/UrlUtils.php

@@ -0,0 +1,101 @@
+<?php
+declare(strict_types=1);
+
+namespace Opentalent\OtCore\Utility;
+
+/**
+ * Building url utilities
+ */
+class UrlUtils
+{
+    /**
+     * Concatenate a base url and a path
+     *
+     * @param string $base The base url
+     * @param array<string> $tails La suite de l'URL sous forme de tableau
+     * @return string
+     */
+    public static function concatPath(string $base, array $tails): string
+    {
+        $url = $base;
+        foreach ($tails as $tail){
+            $url = rtrim($url, '/') . '/' . ltrim(strval($tail), '/');
+        }
+        return $url;
+    }
+
+    /**
+     * Concatenate an url and a list of parameters
+     *
+     * @param string $url
+     * @param list<string | int> $parameters
+     * @return string
+     */
+    public static function concatParameters(string $url, array $parameters = []): string
+    {
+        if (!$parameters) { return $url; }
+        $url = rtrim($url, '?&/');
+        $query = implode(
+            '&',
+            array_map(
+                static function ($k, $v = '') {
+                    $q = urlencode((string)$k);
+                    if ((string)$v) {
+                        $q .= '=' . urlencode((string)$v);
+                    }
+                    return $q;
+                },
+                array_keys($parameters),
+                array_values($parameters)
+            )
+        );
+        return $url . (str_contains($url, '?') ?  '&' : '?') . $query;
+    }
+
+    /**
+     * Prepend the 'https://' part if neither 'http://' of 'https://' is present, else: does nothing
+     *
+     * @param string $url
+     * @return string
+     */
+    public static function prependHttps(string $url): string
+    {
+        if (!preg_match('/^https?:\/\/.*/', $url)) {
+            $url = 'https://' . $url;
+        }
+        return $url;
+    }
+
+    /**
+     * Build an url
+     *
+     * @param string $url The base url
+     * @param array<string> $tails la suite de l'url sous forme de tableau
+     * @param list<string> $parameters A list of parameters (can be an empty array)
+     * @param bool $preprendHttps Should the 'https://' be prepended if missing
+     * @return string
+     */
+    public static function concat(string $url, array $tails, array $parameters, bool $preprendHttps = false): string
+    {
+        $url = self::concatParameters(self::concatPath($url, $tails), $parameters);
+        if ($preprendHttps) {
+            $url = self::prependHttps($url);
+        }
+        return $url;
+    }
+
+    public static function join(string ...$url): string
+    {
+        return self::concatPath($url[0], array_splice($url, 1));
+    }
+
+    public static function normalizePath(string $path): string
+    {
+        return '/' . trim($path, '/');
+    }
+
+    public static function normalizeDomain(string $domain): string
+    {
+        return preg_replace('/https?:\/\/([\w.]+)(?:\/.*)?/', '$1', $domain);
+    }
+}

+ 3 - 2
ot_core/Classes/Website/OtWebsiteRepository.php

@@ -7,6 +7,7 @@ use Opentalent\OtCore\Exception\InvalidWebsiteConfigurationException;
 use Opentalent\OtCore\Exception\NoSuchRecordException;
 use Opentalent\OtCore\Exception\NoSuchWebsiteException;
 use Opentalent\OtCore\Utility\RouteNormalizer;
+use Opentalent\OtCore\Utility\UrlUtils;
 use Psr\Http\Message\UriInterface;
 use Symfony\Component\Yaml\Exception\ParseException;
 use Symfony\Component\Yaml\Yaml;
@@ -345,8 +346,8 @@ class OtWebsiteRepository
             ->select('*')
             ->from('ot_websites');
 
-        $domain = RouteNormalizer::normalizeDomain($uri->getHost());
-        $path = RouteNormalizer::normalizePath($uri->getPath());
+        $domain = UrlUtils::normalizeDomain($uri->getHost());
+        $path = UrlUtils::normalizePath($uri->getPath());
 
         if ($devMode) {
             preg_match("/([\w\-]+)(?:\/.*)?/", $path, $m);

+ 8 - 7
ot_core/ext_localconf.php

@@ -37,13 +37,14 @@ $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['cre
 // In this case we merge them so that the pre-defined vars are not overridden.
 // (/!\ do not forget to clear the cache after any update here)
 $GLOBALS['OT'] = array_merge([
-    'API_BASE_URI' => 'https://api.opentalent.fr',
-    'DB_HOST' => 'prod-back',
+    'API_BASE_URI' => 'http://docker.nginx.opentalent.fr',
+    'DB_HOST' => 'db',
     'DB_USER' => 'dbcloner',
     'DB_PASSWORD' => 'wWZ4hYcrmHLW2mUK',
-    'FRAMES_BASE_URI' => 'https://frames.opentalent.fr',
-    'WEBSITE' => 'https://opentalent.fr',
-    'DASHBOARD_URL' => 'https://admin.opentalent.fr/#/dashboard',
-    'LOGIN_PAGE_URL' => 'https://admin.opentalent.fr/#/login',
-    'FILE_STORAGE_URL' => 'https://api.opentalent.fr/app.php/_internal/secure/files/'
+    'FRAMES_BASE_URI' => 'https://local.frames.opentalent.fr',
+    'WEBSITE' => 'https://local.opentalent.fr',
+    'ADMIN_BASE_URL' => 'https://local.admin.opentalent.fr/',
+    'DASHBOARD_URL' => 'https://local.admin.opentalent.fr/#/dashboard',
+    'LOGIN_PAGE_URL' => 'https://local.admin.opentalent.fr/#/login',
+    'FILE_STORAGE_URL' => 'https://local.api.opentalent.fr/app.php/_internal/secure/files/'
 ], ($GLOBALS['OT'] ?? []));