From 4048d4a8d560e34b1b30e1498840666efc5545e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Mon, 22 Mar 2010 10:11:27 +0000 Subject: [PATCH] Adding support for adding links to login page in authsources.php git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2228 44740490-163a-0410-bde0-09ae8108e29a --- modules/core/lib/Auth/UserPassBase.php | 17 +++++++++++++++++ modules/core/templates/loginuserpass.php | 12 ++++++++++++ modules/core/www/loginuserpass.php | 8 ++++++++ 3 files changed, 37 insertions(+) diff --git a/modules/core/lib/Auth/UserPassBase.php b/modules/core/lib/Auth/UserPassBase.php index 14d809ec2..0b63e9283 100644 --- a/modules/core/lib/Auth/UserPassBase.php +++ b/modules/core/lib/Auth/UserPassBase.php @@ -32,6 +32,12 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source { * If this is NULL, we won't force any username. */ private $forcedUsername; + + /** + * Links to pages from login page. + * From configuration + */ + protected $loginLinks; /** @@ -46,6 +52,10 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source { public function __construct($info, &$config) { assert('is_array($info)'); assert('is_array($config)'); + + if (isset($config['core:loginpage_links'])) { + $this->loginLinks = $config['core:loginpage_links']; + } /* Call the parent constructor first, as required by the interface. */ parent::__construct($info, $config); @@ -62,6 +72,13 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source { $this->forcedUsername = $forcedUsername; } + /** + * Return login links from configuration + */ + public function getLoginLinks() { + return $this->loginLinks; + } + /** * Initialize login. diff --git a/modules/core/templates/loginuserpass.php b/modules/core/templates/loginuserpass.php index 0f3da49ed..cff340c99 100644 --- a/modules/core/templates/loginuserpass.php +++ b/modules/core/templates/loginuserpass.php @@ -93,6 +93,18 @@ foreach ($this->data['stateparams'] as $name => $value) { </form> <?php + +if(!empty($this->data['links'])) { + echo '<ul class="links" style="margin-top: 2em">'; + foreach($this->data['links'] AS $l) { + echo '<li><a href="' . htmlspecialchars($l['href']) . '">' . htmlspecialchars($this->t($l['text'])) . '</a></li>'; + } + echo '</ul>'; +} + + + + echo('<h2>' . $this->t('{login:help_header}') . '</h2>'); echo('<p>' . $this->t('{login:help_text}') . '</p>'); diff --git a/modules/core/www/loginuserpass.php b/modules/core/www/loginuserpass.php index eb6db7448..44a1ae30b 100644 --- a/modules/core/www/loginuserpass.php +++ b/modules/core/www/loginuserpass.php @@ -18,6 +18,13 @@ $authStateId = $_REQUEST['AuthState']; /* Retrieve the authentication state. */ $state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_core_Auth_UserPassBase::STAGEID); + +$source = SimpleSAML_Auth_Source::getById($state[sspmod_core_Auth_UserPassBase::AUTHID]); +if ($source === NULL) { + throw new Exception('Could not find authentication source with id ' . $state[sspmod_core_Auth_UserPassBase::AUTHID]); +} + + if (array_key_exists('username', $_REQUEST)) { $username = $_REQUEST['username']; } elseif (isset($state['core:username'])) { @@ -54,6 +61,7 @@ if (array_key_exists('forcedUsername', $state)) { $t->data['username'] = $username; $t->data['forceUsername'] = FALSE; } +$t->data['links'] = $source->getLoginLinks(); $t->data['errorcode'] = $errorCode; $t->show(); exit(); -- GitLab