use radio buttons to select the login database

allows one click logins to not default databases using passwordmanagers
like keefox.
This commit is contained in:
Mathias Kresin 2015-01-18 01:53:54 +01:00
parent 816b793e4c
commit 76825cb673
4 changed files with 15 additions and 18 deletions

View File

@ -11,9 +11,14 @@ Router\before(function($action) {
Session\open(BASE_URL_DIRECTORY, SESSION_SAVE_PATH, 0);
// Select the requested database. If it fails, logout to destroy session and
// Select the requested database either from post param database or from the
// session variable. If it fails, logout to destroy session and
// 'remember me' cookie
if (! empty($_SESSION['database'])) {
if (! empty(Request\value('database')) && ! Model\Database\select(Request\value('database'))) {
Model\User\logout();
Response\redirect('?action=login');
}
elseif (! empty($_SESSION['database'])) {
if (! Model\Database\select($_SESSION['database'])) {
Model\User\logout();
Response\redirect('?action=login');
@ -29,7 +34,7 @@ Router\before(function($action) {
Response\redirect('?action=login');
}
}
else if (Model\RememberMe\has_cookie()) {
elseif (Model\RememberMe\has_cookie()) {
Model\RememberMe\refresh();
}

View File

@ -229,9 +229,9 @@ function form_radios($name, array $options, array $values = array())
return $html;
}
function form_radio($name, $label, $value, $selected = false, $class = '')
function form_radio($name, $label, $value, $checked = false, $class = '')
{
return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.escape($value).'" '.($selected ? 'selected="selected"' : '').'>'.escape($label).'</label>';
return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.escape($value).'" '.($checked ? 'checked' : '').'>'.escape($label).'</label>';
}
function form_checkbox($name, $label, $value, $checked = false, $class = '')

View File

@ -41,7 +41,7 @@ function select($filename = '')
// function gets called with a filename at least once the database
// connection is established
if ($filename !== '') {
if (! empty($filename)) {
if (ENABLE_MULTIPLE_DB && in_array($filename, get_all())) {
$current_filename = $filename;

View File

@ -34,17 +34,9 @@
<?php if (ENABLE_MULTIPLE_DB && count($databases) > 1): ?>
<div id="database-selector">
<h4><?= t('Select another database') ?></h4>
<ul>
<?php foreach ($databases as $filename => $dbname): ?>
<li>
<?php if ($current_database === $filename): ?>
<strong><?= Helper\escape($dbname) ?></strong>
<?php else: ?>
<a href="?action=select-db&amp;database=<?= Helper\escape($filename) ?>"><?= Helper\escape($dbname) ?></a>
<?php endif ?>
</li>
<?= Helper\form_radio('database', $dbname, $filename, ($current_database === $filename)) ?>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>