Ver código fonte

minor refactoring

Olivier Massot 1 ano atrás
pai
commit
740528bda4

+ 5 - 7
ot_connect/Classes/Service/OtAuthenticationService.php

@@ -10,7 +10,8 @@ use Opentalent\OtCore\Exception\ApiRequestException;
 use Opentalent\OtCore\Logging\OtLogger;
 use Opentalent\OtCore\Service\OpentalentApiService;
 use Opentalent\OtCore\Service\OpentalentEnvService;
-use Opentalent\OtCore\Utility\UrlBuilder;
+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;
@@ -241,13 +242,10 @@ class OtAuthenticationService extends AbstractAuthenticationService
 
             # Redirect the user if the password needs to be changed
             if (isset($data['type']) && $data['type'] === 'change_password') {
-                $redirectTo = UrlBuilder::concat(
-                    OpentalentEnvService::get('ADMIN_BASE_URL'),
-                    ["/account", $data['organization'], "secure/password/", $data['token']],
-                    []
+                $redirectTo = UrlUtils::join(
+                    OpentalentEnvService::get('ADMIN_BASE_URL'), "/#/account/", $data['organization'], "/secure/password/", $data['token']
                 );
-                echo "<body onload=\"window.location.replace('".$redirectTo."')\">";
-                die;
+                NavigationUtils::redirect($redirectTo);
             }
 
             // The API accepted the login request

+ 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);
-    }
-}

+ 16 - 1
ot_core/Classes/Utility/UrlBuilder.php → ot_core/Classes/Utility/UrlUtils.php

@@ -6,7 +6,7 @@ namespace Opentalent\OtCore\Utility;
 /**
  * Building url utilities
  */
-class UrlBuilder
+class UrlUtils
 {
     /**
      * Concatenate a base url and a path
@@ -83,4 +83,19 @@ class UrlBuilder
         }
         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);