Browse Source

FIX: User() -> unserialize

Giancarlo Voci 7 years ago
parent
commit
bac19c8551

+ 1 - 1
package.json

@@ -4,7 +4,7 @@
   "private": true,
   "description": "OM-Link Engine",
   "scripts": {
-    "clean": "rm -rf tmp bundle.css bundle.js ui/css/omlink.css ui/css/omlink.css.map ui/js/omlink.min.js node_modules Site.log",
+    "clean": "shx rm -rf tmp bundle.css bundle.js ui/css/omlink.css ui/css/omlink.css.map ui/js/omlink.min.js node_modules src_minified Site.log cfg/*.bin",
     "build": "node build.js",
     "deploy": "zip -x ui/css/* ui/js/* -9 -r deploy.zip omlink.sql lib cfg/config_prod.bin cfg/labels.ini index.php bundle.* src_minified ui"
   },

+ 15 - 19
src/OpenMind/FindBox/FindBoxService.php

@@ -90,26 +90,22 @@ class FindBoxService
     $labelResponses = $this->findBoxCore->getLabelsFromResponse($fbError);
     $label = &$this->labelToBlink[$labelId];
 
-    if ($labelResponses == NULL) { // Fault error on label maybe because label is not binded or display changing/saveproduct
+    if ($labelResponses && isset($labelResponses[$label->id]) && $labelResponses[$label->id]) { // Label exists and is true, mean that's all OK, no error
+      $label->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
+      $label->tsLastLongBlink = time() + 2;
+      return true;
+    }
+
+    // Ho finito il numero di tentativi massimi?
+    if ($label->retryForFault < 0) {  // Rimuovo dalla coda l'etichetta
+      $this->ServiceLogger->write("Label {$label->id} fatal error. Removing from queue", 'd/m/Y H:i:s');
+      unset($this->labelToBlink[$labelId]);
+    } else {                          // Riprovo al prossimo ciclo
+      $this->ServiceLogger->write("Label {$label->id} blink error. Try next cycle...", 'd/m/Y H:i:s');
+      $label->tsLastLongBlink = 0;
       $label->retryForFault--;
-      // Ho finito il numero di tentativi massimi?
-      if ($label->retryForFault < 0) {  // Rimuovo dalla coda l'etichetta
-        $this->ServiceLogger->write("Label {$label->id} fatal error. Removing from queue", 'd/m/Y H:i:s');
-        unset($this->labelToBlink[$labelId]);
-      } else {                          // Riprovo al prossimo ciclo
-        $this->ServiceLogger->write("Label {$label->id} blink error. Try next cycle...", 'd/m/Y H:i:s');
-        $label->tsLastLongBlink = 0;
-      }
-    } else {  // A valid label id array is returned
-      if (isset($labelResponses[$label->id]) && $labelResponses[$label->id]) { // Label exists and is true, mean that's all OK, no error
-        $label->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
-        $label->tsLastLongBlink = time() + 2;
-        return true;
-      } else { // Retry to blink to next cycle
-        $this->ServiceLogger->write("Label {$label->id} blink error. Try next cycle...", 'd/m/Y H:i:s');
-        $label->tsLastLongBlink = 0;
-      }
     }
+
     return false; // Default return value
   }
 
@@ -144,7 +140,7 @@ class FindBoxService
 
       $this->getCurrentQueue();
 
-      foreach ($this->labelToBlink as $labelId => &$label) {
+      foreach($this->labelToBlink as $labelId => &$label) {
         switch ($label->operation) {
 
           case Q_BLINK_OFF:

+ 1 - 0
src/OpenMind/System/System.php

@@ -122,6 +122,7 @@ class System extends PluginStrategy
       (new Notifications())->Remove($args['code']);
     else
       (new Notifications())->emptyAll();
+
   }
 
   /**

+ 88 - 77
src/OpenMind/System/User.php

@@ -21,81 +21,92 @@ use DB\SQL\Mapper;
  */
 class User extends Mapper
 {
-  private $userRoles;
-
-  /**
-   * User constructor.
-   * @param string/array $where
-   */
-  public function __construct($where)
-  {
-    global $f3;
-    parent::__construct($f3->get('DB'), 'users', NULL, 3600);
-
-    if ($where !== NULL) {
-      $this->load($where);
-      if (!$d = $this->dry())
-        $this->userRoles = unserialize($this->roles);
-    } else
-      $this->userRoles = [];
-  }
-
-  public function generatePassword(string $clearPassword)
-  {
-    return password_hash($this->username . "|$clearPassword", PASSWORD_BCRYPT);
-  }
-
-  /**
-   * Reload user from $_SESSION
-   */
-  public static function Restore()
-  {
-    global $f3;
-
-    $userId = $f3->get('SESSION.user');
-    return new User(['id=?', $userId]);
-
-  }
-
-  /**
-   * Save user in $_SESSION
-   */
-  public function Store()
-  {
-    global $f3;
-    $f3->set('SESSION.user', $this->id);
-  }
-
-  /**
-   * Check if user can do <$permissionName>
-   *
-   * @param string $permissionName
-   * @return bool
-   */
-  public function hasPermission(string $permissionName): bool
-  {
-    if ($this->userRoles)
-      return in_array($permissionName, $this->userRoles);
-    else
-      return false;
-  }
-
-  public function grantPermission(string $permissionName)
-  {
-    if (!in_array($permissionName, $this->userRoles))
-      array_push($this->userRoles, $permissionName);
-  }
-
-  public function removePermission(string $permissionName)
-  {
-    $i = array_search($permissionName, $this->userRoles);
-    if ($i !== false)
-      unset($this->userRoles[$i]);
-  }
-
-  public function save()
-  {
-    $this->roles = serialize($this->userRoles);
-    return parent::save(); // TODO: Change the autogenerated stub
-  }
+    private $userRoles;
+
+    /**
+     * User constructor.
+     * @param string/array $where
+     */
+    public function __construct($where)
+    {
+        global $f3;
+
+        $this->onload(function ($obj) {
+            $obj->userRoles = unserialize($obj->roles);
+        });
+
+        parent::__construct($f3->get('DB'), 'users', NULL, 3600);
+
+        if ($where !== NULL) {
+            $this->load($where);
+        } else
+            $this->userRoles = [];
+    }
+
+    public function generatePassword(string $clearPassword)
+    {
+        return password_hash($this->username . "|$clearPassword", PASSWORD_BCRYPT);
+    }
+
+    /**
+     * Reload user from $_SESSION
+     */
+    public static function Restore()
+    {
+        global $f3;
+
+        $userId = $f3->get('SESSION.user');
+        return new User(['id=?', $userId]);
+
+    }
+
+    /**
+     * Save user in $_SESSION
+     */
+    public function Store()
+    {
+        global $f3;
+        $f3->set('SESSION.user', $this->id);
+    }
+
+    /**
+     * Check if user can do <$permissionName>
+     *
+     * @param string $permissionName
+     * @return bool
+     */
+    public function hasPermission(string $permissionName): bool
+    {
+        if ($this->userRoles)
+            return in_array($permissionName, $this->userRoles);
+        else
+            return false;
+    }
+
+    public function grantPermission(string $permissionName)
+    {
+        if (!in_array($permissionName, $this->userRoles))
+            array_push($this->userRoles, $permissionName);
+    }
+
+    public function removePermission(string $permissionName)
+    {
+        $i = array_search($permissionName, $this->userRoles);
+        if ($i !== false)
+            unset($this->userRoles[$i]);
+    }
+
+    public function save()
+    {
+        $this->roles = serialize($this->userRoles);
+        return parent::save(); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * @return array
+     */
+    public function getRoles(): array
+    {
+        return $this->userRoles;
+    }
 }

+ 1 - 1
ui/js/omlink.js

@@ -78,7 +78,7 @@ function refreshNotificationArea() {
 function NotificationDelete(link, code) {
   fetch(`${BASEURL}/api.system.removenotification/${code}`, {method: "POST"})
     .then(() => {
-      if ((link.length != 0) && (link != '#'))
+      if ((link != null) && (link.length != 0) && (link != '#'))
         window.location.href = `${BASEURL}${link}`;
     })
     .catch(() => {