responsive config login

This commit is contained in:
Roland Gruber 2017-11-04 10:49:28 +01:00
parent 97dc46fb7d
commit 78c4043927
7 changed files with 152 additions and 134 deletions

View File

@ -1511,6 +1511,73 @@ function enforceUserIsLoggedIn($check2ndFactor = true) {
} }
} }
/**
* Prints the content of the header part.
*
* @param string $title page title
* @param string $prefix prefix to LAM main folder (e.g. "..")
*/
function printHeaderContents($title, $prefix) {
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<title>';
echo $title;
echo '</title>';
// include all CSS files
$cssDirName = dirname(__FILE__) . '/../style';
$cssDir = dir($cssDirName);
$cssFiles = array();
$cssEntry = $cssDir->read();
while ($cssEntry !== false) {
if (substr($cssEntry, strlen($cssEntry) - 4, 4) == '.css') {
$cssFiles[] = $cssEntry;
}
$cssEntry = $cssDir->read();
}
sort($cssFiles);
foreach ($cssFiles as $cssEntry) {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$prefix/style/$cssEntry\">";
}
// include responsive CSS
$cssDirName = dirname(__FILE__) . '/../style/responsive';
$cssDir = dir($cssDirName);
$cssFiles = array();
$cssEntry = $cssDir->read();
while ($cssEntry !== false) {
if (substr($cssEntry, strlen($cssEntry) - 4, 4) == '.css') {
$cssFiles[] = $cssEntry;
}
$cssEntry = $cssDir->read();
}
sort($cssFiles);
foreach ($cssFiles as $cssEntry) {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$prefix/style/responsive/$cssEntry\">";
}
echo '<link rel="shortcut icon" type="image/x-icon" href="' . $prefix . '/graphics/favicon.ico">';
echo '<link rel="icon" href="' . $prefix . '/graphics/logo136.png">';
}
/**
* Prints script tags for all LAM JS files.
*
* @param string $prefix prefix to LAM main folder (e.g. "..")
*/
function printJsIncludes($prefix) {
$jsDirName = dirname(__FILE__) . '/../templates/lib';
$jsDir = dir($jsDirName);
$jsFiles = array();
$jsEntry = $jsDir->read();
while ($jsEntry !== false) {
if (substr($jsEntry, strlen($jsEntry) - 3, 3) == '.js') {
$jsFiles[] = $jsEntry;
}
$jsEntry = $jsDir->read();
}
sort($jsFiles);
foreach ($jsFiles as $jsEntry) {
echo "<script type=\"text/javascript\" src=\"$prefix/templates/lib/" . $jsEntry . "\"></script>\n";
}
}
class LAMException extends Exception { class LAMException extends Exception {
private $title; private $title;

View File

@ -338,7 +338,7 @@ function isAccountTypeHidden($type) {
/** /**
* Returns a list of all supported languages. * Returns a list of all supported languages.
* *
* @return array languages * @return LAMLanguage[] languages
*/ */
function getLanguages() { function getLanguages() {
$languages = array(); $languages = array();

View File

@ -231,6 +231,10 @@ table.collapse {
text-align: right; text-align: right;
} }
.text-center {
text-align: center;
}
.bold { .bold {
font-weight: bold; font-weight: bold;
} }
@ -403,7 +407,7 @@ td.loginRightBox {
box-shadow: 2px 2px 5px #a0a0a4; box-shadow: 2px 2px 5px #a0a0a4;
display: inline-block; display: inline-block;
background-color: white; background-color: white;
padding: 20px; padding: 30px;
} }
.limitWidth { .limitWidth {

View File

@ -1,4 +1,15 @@
<?php <?php
namespace LAM\CONFIG;
use \htmlStatusMessage;
use \htmlResponsiveRow;
use \LAMCfgMain;
use \htmlButton;
use \htmlOutputText;
use \htmlLink;
use \htmlDiv;
use \htmlResponsiveSelect;
use \htmlResponsiveInputField;
use \htmlHorizontalLine;
/* /*
$Id$ $Id$
@ -46,7 +57,9 @@ session_regenerate_id(true);
setlanguage(); setlanguage();
// get error message from confmain.php // get error message from confmain.php
if (isset($_SESSION['conf_message'])) $message = $_SESSION['conf_message']; if (isset($_SESSION['conf_message'])) {
$message = $_SESSION['conf_message'];
}
// remove settings from session // remove settings from session
$sessionKeys = array_keys($_SESSION); $sessionKeys = array_keys($_SESSION);
@ -57,47 +70,17 @@ for ($i = 0; $i < sizeof($sessionKeys); $i++) {
echo $_SESSION['header']; echo $_SESSION['header'];
$files = getConfigProfiles(); $files = getConfigProfiles();
?> printHeaderContents(_("Login"), '../..');
<title> if (sizeof($files) < 1) {
<?php $message = new htmlStatusMessage('INFO', _("No server profiles found. Please create one."));
echo _("Login"); }
?> $tabindex = 1;
</title> ?>
<?php
// include all CSS files
$cssDirName = dirname(__FILE__) . '/../../style';
$cssDir = dir($cssDirName);
$cssFiles = array();
$cssEntry = $cssDir->read();
while ($cssEntry !== false) {
if (substr($cssEntry, strlen($cssEntry) - 4, 4) == '.css') {
$cssFiles[] = $cssEntry;
}
$cssEntry = $cssDir->read();
}
sort($cssFiles);
foreach ($cssFiles as $cssEntry) {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/" . $cssEntry . "\">\n";
}
?>
<link rel="shortcut icon" type="image/x-icon" href="../../graphics/favicon.ico">
<link rel="icon" href="../../graphics/logo136.png">
</head> </head>
<body> <body class="admin">
<?php <?php
// include all JavaScript files printJsIncludes('../..');
$jsDirName = dirname(__FILE__) . '/../lib';
$jsDir = dir($jsDirName);
$jsFiles = array();
while ($jsEntry = $jsDir->read()) {
if (substr($jsEntry, strlen($jsEntry) - 3, 3) != '.js') continue;
$jsFiles[] = $jsEntry;
}
sort($jsFiles);
foreach ($jsFiles as $jsEntry) {
echo "<script type=\"text/javascript\" src=\"../lib/" . $jsEntry . "\"></script>\n";
}
// set focus on password field // set focus on password field
?> ?>
<script type="text/javascript" language="javascript"> <script type="text/javascript" language="javascript">
@ -121,93 +104,57 @@ $files = getConfigProfiles();
<br><br> <br><br>
<!-- form to change existing profiles --> <!-- form to change existing profiles -->
<form action="confmain.php" method="post" autocomplete="off"> <form action="confmain.php" method="post" autocomplete="off">
<table align="center"><tr><td>
<table align="center" border="0" rules="none" bgcolor="white" class="ui-corner-all roundedShadowBox"> <?php
<tr>
<td style="border-style:none" rowspan="3" width="20"></td> $row = new htmlResponsiveRow();
<td style="border-style:none" height="20"></td>
<td style="border-style:none" rowspan="3" width="20"></td> // message
</tr> if ($message !== null) {
<tr> $row->add($message, 12);
<td style="border-style:none" align="center"> $row->addVerticalSpacer('2rem');
<b> }
<?php
if (sizeof($files) > 0) { $box = new htmlResponsiveRow();
echo _("Please enter your password to change the server preferences:"); if (sizeof($files) > 0) {
} $box->add(new htmlOutputText(_("Please enter your password to change the server preferences:")), 12);
?> $box->addVerticalSpacer('1.5rem');
</b> $conf = new LAMCfgMain();
</td> $selectedProfile = array();
</tr> $profilesExisting = false;
<tr><td style="border-style:none" >&nbsp;</td></tr> $profiles = $files;
<?php if (!empty($_COOKIE["lam_default_profile"]) && in_array($_COOKIE["lam_default_profile"], $files)) {
if (sizeof($files) < 1) $message = _("No server profiles found. Please create one."); $selectedProfile[] = $_COOKIE["lam_default_profile"];
// print message if login was incorrect or no config profiles are present }
if (isset($message)) { // $message is set by confmain.php (requires conflogin.php then) else {
echo "<tr>\n"; $selectedProfile[] = $conf->default;
echo "<td style=\"border-style:none\" rowspan=\"2\"></td>\n"; }
echo "<td style=\"border-style:none\" align=\"center\"><b><font color=red>" . $message . "</font></b></td>\n"; $box->add(new htmlResponsiveSelect('filename', $profiles, $selectedProfile, _('Profile name')), 12);
echo "<td style=\"border-style:none\" rowspan=\"2\"></td>\n"; $passwordInput = new htmlResponsiveInputField(_('Password'), 'passwd', '', '200');
echo "</tr>\n"; $passwordInput->setIsPassword(true);
echo "<tr>\n"; $box->add($passwordInput, 12);
echo "<td style=\"border-style:none\" >&nbsp;</td>\n"; $box->addVerticalSpacer('1rem');
echo "</tr>\n"; $button = new htmlButton('submit', _("Ok"));
} $box->addLabel($button);
?> $box->add(new htmlOutputText(''), 0, 6);
<tr> $box->addVerticalSpacer('1.5rem');
<td style="border-style:none" rowspan="4" width="20"></td> $box->add(new htmlHorizontalLine(), 12);
<td style="border-style:none" align="center"> $box->addVerticalSpacer('1.5rem');
<?php }
$conf = new LAMCfgMain(); $box->add(new htmlLink(_("Manage server profiles"), 'profmanage.php'), 12, 12, 12, 'text-center');
$group = new htmlTable();
$profiles = array(); $boxDiv = new htmlDiv(null, $box);
$selectedProfile = array(); $boxDiv->setCSSClasses(array('ui-corner-all', 'roundedShadowBox', 'limitWidth'));
$profilesExisting = false; $row->add($boxDiv, 12);
if (sizeof($files) > 0) {
$profiles = $files; // back link
if (!empty($_COOKIE["lam_default_profile"]) && in_array($_COOKIE["lam_default_profile"], $files)) { $row->addVerticalSpacer('2rem');
$selectedProfile[] = $_COOKIE["lam_default_profile"]; $backLink = new htmlLink(_("Back to login"), '../login.php', '../../graphics/undo.png');
} $row->add($backLink, 12, 12, 12, 'text-left');
else {
$selectedProfile[] = $conf->default; parseHtml(null, $row, array(), false, $tabindex, 'user');
}
$profilesExisting = true; ?>
$select = new htmlSelect('filename', $profiles, $selectedProfile);
$select->setIsEnabled($profilesExisting);
$group->addElement($select);
$passwordField = new htmlInputField('passwd');
$passwordField->setIsPassword(true);
$passwordField->setIsEnabled($profilesExisting);
$passwordField->setFieldSize(20);
$group->addElement($passwordField);
$button = new htmlButton('submit', _("Ok"));
$button->setIsEnabled($profilesExisting);
$group->addElement($button);
$group->addElement(new htmlHelpLink('200'));
$tabindex = 1;
parseHtml(null, $group, array(), false, $tabindex, 'user');
}
?>
</td>
<td style="border-style:none" rowspan="4" width="20"></td>
</tr>
<tr>
<td style="border-style:none">&nbsp;</td>
</tr>
<tr>
<td style="border-style:none" align="center">
<b><a href="profmanage.php"><?php echo _("Manage server profiles") ?></a></b>
</td>
</tr>
<tr>
<td style="border-style:none" height="20"></td>
</tr>
</table>
</td></tr>
<tr><td>
<br><a href="../login.php"><IMG alt="configuration" src="../../graphics/undo.png">&nbsp;<?php echo _("Back to login"); ?> </a>
</td></tr>
</table>
</form> </form>
<p><br><br></p> <p><br><br></p>

View File

@ -19,7 +19,6 @@ use \htmlElement;
use \htmlSubTitle; use \htmlSubTitle;
use \htmlButton; use \htmlButton;
/* /*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2017 Roland Gruber Copyright (C) 2003 - 2017 Roland Gruber
@ -73,7 +72,7 @@ if (isset($_POST['passwd'])) $passwd = $_POST['passwd'];
// check if password was entered // check if password was entered
// if not: load login page // if not: load login page
if (!isset($passwd) && !(isset($_SESSION['conf_isAuthenticated']) && isset($_SESSION['conf_config']))) { if (!isset($passwd) && !(isset($_SESSION['conf_isAuthenticated']) && isset($_SESSION['conf_config']))) {
$_SESSION['conf_message'] = _("No password was entered!"); $_SESSION['conf_message'] = new htmlStatusMessage('ERROR', _("No password was entered!"));
/** go back to login if password is empty */ /** go back to login if password is empty */
metaRefresh('conflogin.php'); metaRefresh('conflogin.php');
exit; exit;
@ -91,7 +90,7 @@ if ((!isset($_SESSION['conf_isAuthenticated']) || !($_SESSION['conf_isAuthentica
for ($i = 0; $i < sizeof($sessionKeys); $i++) { for ($i = 0; $i < sizeof($sessionKeys); $i++) {
if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]); if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]);
} }
$_SESSION['conf_message'] = _("The password is invalid! Please try again."); $_SESSION['conf_message'] = new htmlStatusMessage('ERROR', _("The password is invalid! Please try again."));
/** go back to login if password is invalid */ /** go back to login if password is invalid */
metaRefresh('conflogin.php'); metaRefresh('conflogin.php');
exit; exit;

View File

@ -1,6 +1,7 @@
<?php <?php
namespace LAM\CONFIG; namespace LAM\CONFIG;
use \LAMConfig; use \LAMConfig;
use \htmlStatusMessage;
/* /*
$Id$ $Id$
@ -52,7 +53,7 @@ if (isset($_POST['passwd'])) $passwd = $_POST['passwd'];
// check if password was entered // check if password was entered
// if not: load login page // if not: load login page
if (!isset($passwd) && !isset($_SESSION['conf_isAuthenticated'])) { if (!isset($passwd) && !isset($_SESSION['conf_isAuthenticated'])) {
$_SESSION['conf_message'] = _("No password was entered!"); $_SESSION['conf_message'] = new htmlStatusMessage('ERROR', _("No password was entered!"));
/** go back to login if password is empty */ /** go back to login if password is empty */
require('conflogin.php'); require('conflogin.php');
exit; exit;
@ -70,7 +71,7 @@ if ((!isset($_SESSION['conf_isAuthenticated']) || !($_SESSION['conf_isAuthentica
for ($i = 0; $i < sizeof($sessionKeys); $i++) { for ($i = 0; $i < sizeof($sessionKeys); $i++) {
if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]); if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]);
} }
$_SESSION['conf_message'] = _("The password is invalid! Please try again."); $_SESSION['conf_message'] = new htmlStatusMessage('ERROR', _("The password is invalid! Please try again."));
/** go back to login if password is invalid */ /** go back to login if password is invalid */
require('conflogin.php'); require('conflogin.php');
exit; exit;

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2016 Roland Gruber Copyright (C) 2003 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by