Skip to content
Snippets Groups Projects
Commit 37c590a6 authored by Olav Morken's avatar Olav Morken
Browse files

multiauth: Move focus to the last selected authsource.

This patch changes multiauth to display a list of buttons, and moves
focus to the last authsource selected.

Thanks to Lorenzo Gil Sanchez for implementing this!

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2894 44740490-163a-0410-bde0-09ae8108e29a
parent 7c5e8647
No related branches found
No related tags found
No related merge requests found
...@@ -186,6 +186,44 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source { ...@@ -186,6 +186,44 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source {
$source->logout($state); $source->logout($state);
} }
/**
* Set the previous authentication source.
*
* This method remembers the authentication source that the user selected
* by storing its name in a cookie.
*
* @param string $source Name of the authentication source the user selected.
*/
public function setPreviousSource($source) {
assert('is_string($source)');
$cookieName = 'multiauth_source_' . $this->authId;
/* We save the cookies for 90 days. */
$saveUntil = time() + 60*60*24*90;
/* The base path for cookies.
This should be the installation directory for simpleSAMLphp. */
$config = SimpleSAML_Configuration::getInstance();
$cookiePath = '/' . $config->getBaseUrl();
setcookie($cookieName, $source, $saveUntil, $cookiePath);
}
/**
* Get the previous authentication source.
*
* This method retrieves the authentication source that the user selected
* last time or NULL if this is the first time or remembering is disabled.
*/
public function getPreviousSource() {
$cookieName = 'multiauth_source_' . $this->authId;
if(array_key_exists($cookieName, $_COOKIE)) {
return $_COOKIE[$cookieName];
} else {
return NULL;
}
}
} }
?> ?>
...@@ -8,15 +8,25 @@ $this->includeAtTemplateBase('includes/header.php'); ...@@ -8,15 +8,25 @@ $this->includeAtTemplateBase('includes/header.php');
<p><?php echo $this->t('{multiauth:multiauth:select_source_text}'); ?></p> <p><?php echo $this->t('{multiauth:multiauth:select_source_text}'); ?></p>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="get">
<input type="hidden" name="AuthState" value="<?php echo htmlspecialchars($this->data['authstate']); ?>" />
<ul> <ul>
<?php <?php
foreach($this->data['sources'] as $source) { foreach($this->data['sources'] as $source) {
echo '<li class="' . htmlspecialchars($source['css_class']) . ' authsource">' . echo '<li class="' . htmlspecialchars($source['css_class']) . ' authsource">';
'<a href="?source=' . htmlspecialchars($source['source']) . if ($source['source'] === $this->data['preferred']) {
'&AuthState=' . htmlspecialchars($this->data['authstate']) . '">' . $autofocus = ' autofocus="autofocus"';
'<span>' . htmlspecialchars($this->t($source['text'])) . '</span></a></li>'; } else {
$autofocus = '';
}
echo '<button type="submit" name="source"' . $autofocus . ' ' .
'id="button-' . htmlspecialchars($source['source']) . '" ' .
'value="' . htmlspecialchars($source['source']) . '">';
echo htmlspecialchars($this->t($source['text']));
echo '</button>';
echo '</li>';
} }
?> ?>
</ul> </ul>
</form>
<?php $this->includeAtTemplateBase('includes/footer.php'); ?> <?php $this->includeAtTemplateBase('includes/footer.php'); ?>
...@@ -19,8 +19,18 @@ $authStateId = $_REQUEST['AuthState']; ...@@ -19,8 +19,18 @@ $authStateId = $_REQUEST['AuthState'];
/* Retrieve the authentication state. */ /* Retrieve the authentication state. */
$state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID); $state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID);
if (array_key_exists("SimpleSAML_Auth_Default.id", $state)) {
$authId = $state["SimpleSAML_Auth_Default.id"];
$as = SimpleSAML_Auth_Source::getById($authId);
} else {
$as = NULL;
}
if (array_key_exists('source', $_REQUEST)) { if (array_key_exists('source', $_REQUEST)) {
$source = $_REQUEST['source']; $source = $_REQUEST['source'];
if ($as !== NULL) {
$as->setPreviousSource($source);
}
sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state); sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state);
} elseif (array_key_exists('multiauth:preselect', $state)) { } elseif (array_key_exists('multiauth:preselect', $state)) {
$source = $state['multiauth:preselect']; $source = $state['multiauth:preselect'];
...@@ -31,6 +41,11 @@ $globalConfig = SimpleSAML_Configuration::getInstance(); ...@@ -31,6 +41,11 @@ $globalConfig = SimpleSAML_Configuration::getInstance();
$t = new SimpleSAML_XHTML_Template($globalConfig, 'multiauth:selectsource.php'); $t = new SimpleSAML_XHTML_Template($globalConfig, 'multiauth:selectsource.php');
$t->data['authstate'] = $authStateId; $t->data['authstate'] = $authStateId;
$t->data['sources'] = $state[sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID]; $t->data['sources'] = $state[sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID];
if ($as !== NULL) {
$t->data['preferred'] = $as->getPreviousSource();
} else {
$t->data['preferred'] = NULL;
}
$t->show(); $t->show();
exit(); exit();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment