]> BookStack Code Mirror - bookstack/blobdiff - app/User.php
Added ability to secure images behind auth
[bookstack] / app / User.php
index 09b189cbb55e084419309c3b6f154e77ed28d4ee..fd6879ba007dc1d551b7385c6a93c043aebc98db 100644 (file)
@@ -74,6 +74,16 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
         return $this->roles->pluck('name')->contains($role);
     }
 
+    /**
+     * Check if the user has a role.
+     * @param $role
+     * @return mixed
+     */
+    public function hasSystemRole($role)
+    {
+        return $this->roles->pluck('system_name')->contains($role);
+    }
+
     /**
      * Get all permissions belonging to a the current user.
      * @param bool $cache
@@ -150,8 +160,16 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
      */
     public function getAvatar($size = 50)
     {
-        if ($this->image_id === 0 || $this->image_id === '0' || $this->image_id === null) return baseUrl('/user_avatar.png');
-        return baseUrl($this->avatar->getThumb($size, $size, false));
+        $default = baseUrl('/user_avatar.png');
+        $imageId = $this->image_id;
+        if ($imageId === 0 || $imageId === '0' || $imageId === null) return $default;
+
+        try {
+            $avatar = $this->avatar ? baseUrl($this->avatar->getThumb($size, $size, false)) : $default;
+        } catch (\Exception $err) {
+            $avatar = $default;
+        }
+        return $avatar;
     }
 
     /**