[icinga-checkins] icinga.org: icingaweb2/bugfix/ username-and-password-not-being-passed-in-navigation-item-urls-12133: Url: Add username and password to method getBaseUrl

git at icinga.org git at icinga.org
Tue Oct 18 16:19:43 CEST 2016


Module: icingaweb2
Branch: bugfix/username-and-password-not-being-passed-in-navigation-item-urls-12133
Commit: a952a400ca84cef24157aff83dfc94e059352f53
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=a952a400ca84cef24157aff83dfc94e059352f53

Author: Noah Hilverling <noah.hilverling at netways.de>
Date:   Tue Oct 18 16:16:13 2016 +0200

Url: Add username and password to method getBaseUrl

refs #12133

---

 library/Icinga/Web/Url.php |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php
index 4128a23..3bc9756 100644
--- a/library/Icinga/Web/Url.php
+++ b/library/Icinga/Web/Url.php
@@ -410,11 +410,27 @@ class Url
      */
     public function getBaseUrl()
     {
-        if (!$this->isExternal()) {
+        if (! $this->isExternal()) {
             return $this->getBasePath();
         }
 
-        return $this->getScheme() . '://' . $this->getHost() . ($this->getPort() ? (':' . $this->getPort()) : '');
+        $urlString = '';
+        if ($this->getScheme()) {
+            $urlString .= $this->getScheme() . '://';
+        }
+        if ($this->getPassword()) {
+            $urlString .= $this->getUsername() . ':' . $this->getPassword() . '@';
+        } elseif ($this->getUsername()) {
+            $urlString .= $this->getUsername() . '@';
+        }
+        if ($this->getHost()) {
+            $urlString .= $this->getHost();
+        }
+        if ($this->getPort()) {
+            $urlString .= ':' . $this->getPort();
+        }
+
+        return $urlString;
     }
 
     /**



More information about the icinga-checkins mailing list