base URL for self service
This commit is contained in:
parent
2ac5b95e63
commit
19ea7dd3dd
|
@ -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"),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/*
|
||||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2019 Roland Gruber
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
require_once 'lam/lib/selfService.inc';
|
||||
|
||||
/**
|
||||
* Checks selfServiceProfile.
|
||||
*
|
||||
* @author Roland Gruber
|
||||
*
|
||||
*/
|
||||
class selfServiceProfileTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testBaseUrl() {
|
||||
$profile = new selfServiceProfile();
|
||||
$profile->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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue