diff --git a/lam/help/help.inc b/lam/help/help.inc index ede21b37..40a22f79 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -133,6 +133,8 @@ $helpArray = array ( "Text" => _("If enabled then LAM will use user and password that is provided by the web server via HTTP authentication.")), "224" => array ("Headline" => _("Bind user and password"), "Text" => _("Here you can specify the DN and password of the bind user that will be used for the LDAP search. This is required if your LDAP server does not allow anonymous access.")), + "225" => array ("Headline" => _('Base URL'), + "Text" => _("Please enter the base URL of your webserver (e.g. https://www.example.com). This is used to generate links in emails.")), "230" => array ("Headline" => _("Profile management") . " - " . _("Add profile"), "Text" => _("Please enter the name of the new profile and the password to change its settings. Profile names may contain letters, numbers and -/_.")), "231" => array ("Headline" => _("Profile management") . " - " . _("Rename profile"), diff --git a/lam/lib/selfService.inc b/lam/lib/selfService.inc index 0bcf4c41..af5205a4 100644 --- a/lam/lib/selfService.inc +++ b/lam/lib/selfService.inc @@ -455,6 +455,9 @@ class selfServiceProfile { /** enable captcha on self service login */ public $captchaOnLogin = false; + /** base URL for the website (e.g. https://example.com) for link generation */ + private $baseUrl = ''; + /** * Constructor * @@ -505,6 +508,35 @@ class selfServiceProfile { $this->reCaptchaSiteKey = ''; $this->reCaptchaSecretKey = ''; $this->captchaOnLogin = false; + $this->baseUrl = ''; + } + + /** + * Returns the server's base URL (e.g. https://www.example.com). + * + * @return string URL + */ + public function getBaseUrl() { + if (!empty($this->baseUrl)) { + return $this->baseUrl; + } + $callingUrl = getCallingURL(); + $matches = array(); + if (preg_match('/^(http(s)?:\\/\\/[^\\/]+)\\/.+$/', $callingUrl, $matches)) { + return $matches[1]; + } + } + + /** + * Sets the server's base URL (e.g. https://www.example.com). + * + * @param string $url URL + */ + public function setBaseUrl($url) { + $this->baseUrl = $url; + if (!empty($url) && (substr($url, -1, 1) === '/')) { + $this->baseUrl = substr($url, 0, -1); + } } } diff --git a/lam/tests/lib/selfServiceTest.php b/lam/tests/lib/selfServiceTest.php new file mode 100644 index 00000000..13abe000 --- /dev/null +++ b/lam/tests/lib/selfServiceTest.php @@ -0,0 +1,47 @@ +setBaseUrl('http://test.com/'); + $this->assertEquals('http://test.com', $profile->getBaseUrl()); + $profile->setBaseUrl('http://test.com'); + $this->assertEquals('http://test.com', $profile->getBaseUrl()); + $profile->setBaseUrl('https://test.com/'); + $this->assertEquals('https://test.com', $profile->getBaseUrl()); + $profile->setBaseUrl('https://test.com'); + $this->assertEquals('https://test.com', $profile->getBaseUrl()); + } + +} + +?> \ No newline at end of file