]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6913 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 May 2024 13:06:48 +0000 (15:06 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 May 2024 13:06:48 +0000 (15:06 +0200)
app/Fluidbook/Compiler/Secure.php
app/Models/FluidbookPublication.php

index 3f5bc39fdf1889a9183795bc7d4ee4f55beadcac..add45a2c58f9d9a0a02d064a4a1ca40c48256f7b 100644 (file)
@@ -21,7 +21,9 @@ trait Secure
     protected function _getSecureUsers()
     {
         $credentials = Text::explodeNewLines(trim($this->fluidbookSettings->secureClientSidePasswordCredentials));
-        if ($this->fluidbookSettings->secureClientSideMode == '1') {
+        $mode = $this->fluidbookSettings->secureClientSideMode ?? '0';
+
+        if ($mode == '1') {
             $credentials[] = 'fluidbook';
         } else {
             $credentials[] = 'fluidbook:LatacaM4##*';
@@ -30,13 +32,13 @@ trait Secure
         foreach ($credentials as $credential) {
             $salt = bin2hex(random_bytes(5));
             $e = explode(':', $credential);
-            if ($this->fluidbookSettings->secureClientSideMode == '0' && count($e) <= 1) {
+            if ($mode == '0' && count($e) <= 1) {
                 continue;
             }
             $usersalt = bin2hex(random_bytes(5));
             $user = hash("sha256", $usersalt . '+' . mb_strtolower($e[0]));
             $u = ['salt' => $salt, 'usersalt' => $usersalt];
-            if (count($e) > 1 && $this->fluidbookSettings->secureClientSideMode != '0') {
+            if (count($e) > 1 && $mode == '0') {
                 $u['hash'] = hash("sha256", $salt . '-' . Text::removeAccents($e[1]));
             }
             $users[$user] = $u;
index 545468dce5c1f2d5603213ab1a03b5db34e1ac16..90034e6a80ee516d2cdac341c2cae171f1e84e32 100644 (file)
@@ -1033,6 +1033,12 @@ class FluidbookPublication extends ToolboxStatusModel
         return $res;
     }
 
+    public function onRetrieved(): bool
+    {
+        $this->setDefaults();
+        return parent::onRetrieved();
+    }
+
     public function getAnchorsFromExcel()
     {
         $res = [];
@@ -1117,7 +1123,15 @@ class FluidbookPublication extends ToolboxStatusModel
             $version = 3;
         }
         $this->version = $version;
-        $fields = ['imageFormat', 'secureClientSidePassword', 'relay_url_params'];
+        $this->setDefaults();
+        $this->save();
+
+        DB::update('UPDATE ' . WorkshopMigration::OLD_DB . '.books SET version=' . $version . ' WHERE book_id=' . $this->id);
+    }
+
+    public function setDefaults()
+    {
+        $fields = ['imageFormat', 'secureClientSidePassword', 'secureClientSideMode', 'relay_url_params'];
         foreach ($fields as $n) {
             $f = $this->getField($n);
             if (null === $this->{$n}) {
@@ -1125,9 +1139,6 @@ class FluidbookPublication extends ToolboxStatusModel
             }
         }
         $this->svgToCanvas = !$this->svgToCanvas ? 0 : 1;
-        $this->save();
-
-        DB::update('UPDATE ' . WorkshopMigration::OLD_DB . '.books SET version=' . $version . ' WHERE book_id=' . $this->id);
     }
 
     public function generateThumbnailsPreview($sync = false)