Просмотр исходного кода

Fix: Could not add picture see #88 (#89)

Marcel 1 год назад
Родитель
Сommit
2c83a54f01
2 измененных файлов с 11 добавлено и 4 удалено
  1. 5 2
      inc/provider.class.php
  2. 6 2
      inc/toolbox.class.php

+ 5 - 2
inc/provider.class.php

@@ -868,8 +868,10 @@ class PluginSinglesignonProvider extends CommonDBTM {
 
       $url = $fields['url_resource_owner_details'];
 
-      $url = str_replace("<access_token>", $access_token, $url);
-      $url = str_replace("<appsecret_proof>", hash_hmac('sha256', $access_token, $this->getClientSecret()), $url);
+      if (!IS_NULL($access_token)) {
+         $url = str_replace("<access_token>", $access_token, $url);
+         $url = str_replace("<appsecret_proof>", hash_hmac('sha256', $access_token, $this->getClientSecret()), $url);
+      }
 
       return $url;
    }
@@ -1257,6 +1259,7 @@ class PluginSinglesignonProvider extends CommonDBTM {
             'realname' => $realname,
             'firstname' => $firstname,
             //'picture' => $resource_array['picture'] ?? '',
+            'picture' => $resource_array['picture'],
             'api_token' => $tokenAPI,
             'personal_token' => $tokenPersonnel,
             'is_active' => 1

+ 6 - 2
inc/toolbox.class.php

@@ -111,7 +111,7 @@ class PluginSinglesignonToolbox {
       return $CFG_GLPI['root_doc'] . '/plugins/singlesignon/front/picture.send.php?path=' . $path;
    }
 
-   static public function savePicture($src, $uniq_prefix = null) {
+   static public function savePicture($src, $uniq_prefix = "") {
 
       if (function_exists('Document::isImage') && !Document::isImage($src)) {
          return false;
@@ -131,7 +131,11 @@ class PluginSinglesignonToolbox {
          . '/' . $filename . ($i > 0 ? '_' . $i : '') . '.' . $ext;
          $i++;
       } while (file_exists($dest));
-
+      // If the base directory does not exists, create it
+      if (!is_dir($basePath) && !mkdir($basePath)) {
+         return false;
+      }
+      // If the sub directory does not exists, create the sub directory
       if (!is_dir($basePath . '/' . $subdirectory) && !mkdir($basePath . '/' . $subdirectory)) {
          return false;
       }