Edgard před 3 roky
rodič
revize
dfe9bb78bd
4 změnil soubory, kde provedl 40 přidání a 33 odebrání
  1. 5 2
      composer.json
  2. 17 21
      hook.php
  3. 12 8
      inc/provider.class.php
  4. 6 2
      inc/toolbox.class.php

+ 5 - 2
composer.json

@@ -15,9 +15,12 @@
         "update-locales": "@php tools/update-locales.php"
     },
     "config": {
-        "sort-packages": true,
+        "allow-plugins": {
+            "dealerdirect/phpcodesniffer-composer-installer": true
+        },
         "platform": {
             "php": "7.1.2"
-        }
+        },
+        "sort-packages": true
     }
 }

+ 17 - 21
hook.php

@@ -169,31 +169,27 @@ function plugin_singlesignon_install() {
 
       $DB->query($query) or die("error creating glpi_plugin_singlesignon_providers " . $DB->error());
    } else {
-		$query = "SHOW COLUMNS FROM glpi_plugin_singlesignon_providers LIKE 'is_default'";
-		$result = $DB->query($query) or die($DB->error());
-		if ($DB->numrows($result) != 1)
-		{
-			$DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD is_default tinyint(1) NOT NULL DEFAULT '0'") or die ($DB->error());
-		}
+      $query = "SHOW COLUMNS FROM glpi_plugin_singlesignon_providers LIKE 'is_default'";
+      $result = $DB->query($query) or die($DB->error());
+      if ($DB->numrows($result) != 1) {
+         $DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD is_default tinyint(1) NOT NULL DEFAULT '0'") or die ($DB->error());
+      }
 
       $query = "SHOW COLUMNS FROM glpi_plugin_singlesignon_providers LIKE 'popup'";
-		$result = $DB->query($query) or die($DB->error());
-		if ($DB->numrows($result) != 1)
-		{
-			$DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD popup tinyint(1) NOT NULL DEFAULT '0'") or die ($DB->error());
-		}
+      $result = $DB->query($query) or die($DB->error());
+      if ($DB->numrows($result) != 1) {
+         $DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD popup tinyint(1) NOT NULL DEFAULT '0'") or die ($DB->error());
+      }
       $query = "SHOW COLUMNS FROM glpi_plugin_singlesignon_providers LIKE 'split_domain'";
-		$result = $DB->query($query) or die($DB->error());
-		if ($DB->numrows($result) != 1)
-		{
-			$DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD split_domain tinyint(1) NOT NULL DEFAULT '0'") or die ($DB->error());
-		}
+      $result = $DB->query($query) or die($DB->error());
+      if ($DB->numrows($result) != 1) {
+         $DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD split_domain tinyint(1) NOT NULL DEFAULT '0'") or die ($DB->error());
+      }
       $query = "SHOW COLUMNS FROM glpi_plugin_singlesignon_providers LIKE 'authorized_domains'";
-		$result = $DB->query($query) or die($DB->error());
-		if ($DB->numrows($result) != 1)
-		{
-			$DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD authorized_domains varchar(255) COLLATE utf8_unicode_ci NULL") or die ($DB->error());
-		}
+      $result = $DB->query($query) or die($DB->error());
+      if ($DB->numrows($result) != 1) {
+         $DB->query("ALTER TABLE glpi_plugin_singlesignon_providers ADD authorized_domains varchar(255) COLLATE utf8_unicode_ci NULL") or die ($DB->error());
+      }
    }
 
    // add display preferences

+ 12 - 8
inc/provider.class.php

@@ -1092,11 +1092,13 @@ class PluginSinglesignonProvider extends CommonDBTM {
             $login = $resource_array[$field];
             $isAuthorized = empty($authorizedDomains);
             foreach ($authorizedDomains as $authorizedDomain) {
-              if(preg_match("/{$authorizedDomain}$/i", $login)) {
-                 $isAuthorized = true;
-              }
+               if (preg_match("/{$authorizedDomain}$/i", $login)) {
+                  $isAuthorized = true;
+               }
+            }
+            if (!$isAuthorized) {
+               return false;
             }
-            if (!$isAuthorized) return false;
             if ($split) {
                $loginSplit = explode("@", $login);
                $login = $loginSplit[0];
@@ -1122,11 +1124,13 @@ class PluginSinglesignonProvider extends CommonDBTM {
             $email = $resource_array[$field];
             $isAuthorized = empty($authorizedDomains);
             foreach ($authorizedDomains as $authorizedDomain) {
-              if(preg_match("/{$authorizedDomain}$/i", $email)) {
-                 $isAuthorized = true;
-              }
+               if (preg_match("/{$authorizedDomain}$/i", $email)) {
+                  $isAuthorized = true;
+               }
+            }
+            if (!$isAuthorized) {
+               return false;
             }
-            if (!$isAuthorized) return false;
             if ($split) {
                $emailSplit = explode("@", $email);
                $email = $emailSplit[0];

+ 6 - 2
inc/toolbox.class.php

@@ -25,7 +25,9 @@ class PluginSinglesignonToolbox {
 
    public static function isDefault($row, $query = []) {
 
-      if ($row['is_default'] == 1) return true;
+      if ($row['is_default'] == 1) {
+         return true;
+      }
       return false;
    }
 
@@ -134,7 +136,9 @@ class PluginSinglesignonToolbox {
 
    public static function renderButton($url, $data, $class = 'oauth-login') {
       $popupClass = "";
-      if (isset($data['popup']) && $data['popup'] == 1) $popupClass = "popup";
+      if (isset($data['popup']) && $data['popup'] == 1) {
+         $popupClass = "popup";
+      }
       $btn = '<span><a href="' . $url . '" class="singlesignon vsubmit ' . $class . ' ' . $popupClass . '"';
 
       $style = '';