From fba01c0ada5b3c7b22506928990ee2d87c9a6855 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 25 May 2014 14:37:05 +0000 Subject: [PATCH] added graphical hint if password values are not equal --- lam/lib/html.inc | 20 ++++++++++++++++ lam/lib/modules.inc | 1 + lam/lib/modules/posixAccount.inc | 1 + lam/lib/modules/sambaSamAccount.inc | 1 + lam/lib/modules/windowsUser.inc | 1 + lam/style/500_layout.css | 7 ++++++ lam/templates/config/confmain.php | 1 + lam/templates/config/mainmanage.php | 1 + lam/templates/config/profmanage.php | 4 +++- lam/templates/lib/500_lam.js | 37 +++++++++++++++++++++++++++-- 10 files changed, 71 insertions(+), 3 deletions(-) diff --git a/lam/lib/html.inc b/lam/lib/html.inc index 2c4899cf..c60403e3 100644 --- a/lam/lib/html.inc +++ b/lam/lib/html.inc @@ -448,6 +448,8 @@ class htmlInputField extends htmlElement { protected $calendarFormat = ''; /** title attribute */ protected $title = null; + /** field ID that needs to have same value (e.g. password field) */ + protected $sameValueFieldID = null; /** * Constructor @@ -570,6 +572,7 @@ class htmlInputField extends htmlElement { echo '});'; echo ""; } + // calendar if ($this->showCalendar) { echo ' '; } + // check value against reference field + if ($this->sameValueFieldID != null) { + echo ' + '; + } if ($this->transient) { return array(); } @@ -711,6 +721,16 @@ class htmlInputField extends htmlElement { $this->title = htmlspecialchars($title); } + /** + * Specifies the ID of a second field that must have the same value as this field. + * This field is marked red if different or green if equal. + * + * @param String $sameValueFieldID ID of reference field + */ + public function setSameValueFieldID($sameValueFieldID) { + $this->sameValueFieldID = $sameValueFieldID; + } + } /** diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index deb71789..598601a0 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1048,6 +1048,7 @@ class accountContainer { $container->addElement(new htmlOutputText(_('Repeat password'))); $pwdInput2 = new htmlInputField('newPassword2'); $pwdInput2->setIsPassword(true); + $pwdInput2->setSameValueFieldID('newPassword1'); $container->addElement($pwdInput2, true); // print force password change option $forceChangeSupported = false; diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index d60749f0..f25ea901 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -2532,6 +2532,7 @@ class posixAccount extends baseModule implements passwordService { $pwdTable->addElement($pwd1, true); $pwd2 = new htmlTableExtendedInputField(_('Reenter password'), 'posixAccount_password2'); $pwd2->setIsPassword(true); + $pwd2->setSameValueFieldID('posixAccount_password'); $pwdTable->addElement($pwd2); $return['password'] = new htmlTableRow(array( $pwdTable diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 96c7c71d..c90a3368 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -2267,6 +2267,7 @@ class sambaSamAccount extends baseModule implements passwordService { $pwdTable->addElement($pwd1, true); $pwd2 = new htmlTableExtendedInputField(_('Reenter password'), 'sambaSamAccount_password2'); $pwd2->setIsPassword(true); + $pwd2->setSameValueFieldID('sambaSamAccount_password'); $pwdTable->addElement($pwd2); $return['password'] = new htmlTableRow(array( $pwdTable diff --git a/lam/lib/modules/windowsUser.inc b/lam/lib/modules/windowsUser.inc index b69a6255..a51f84fa 100644 --- a/lam/lib/modules/windowsUser.inc +++ b/lam/lib/modules/windowsUser.inc @@ -1713,6 +1713,7 @@ class windowsUser extends baseModule implements passwordService { $pwdTable->addElement($pwd1, true); $pwd2 = new htmlTableExtendedInputField(_('Reenter password'), 'windowsUser_unicodePwd2'); $pwd2->setIsPassword(true); + $pwd2->setSameValueFieldID('windowsUser_unicodePwd'); $pwdTable->addElement($pwd2); $return['unicodePwd'] = new htmlTableRow(array( $pwdTable diff --git a/lam/style/500_layout.css b/lam/style/500_layout.css index 0d938b69..f6755fa7 100644 --- a/lam/style/500_layout.css +++ b/lam/style/500_layout.css @@ -288,6 +288,13 @@ a.lamLogo { margin-left: 5px; } +input.markFail { + background-color: #ffc4ba; +} +input.markOk { + background-color: #abebaa; +} + .sortableList { list-style-type: none; margin: 0; padding: 0; } .sortableList li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; } .sortableList li span { position: absolute; margin-left: -1.3em; } diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 64c34bcb..85ff2a2c 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -452,6 +452,7 @@ $password1 = new htmlTableExtendedInputField(_("New password"), 'passwd1', null, $password1->setIsPassword(true); $password2 = new htmlTableExtendedInputField(_("Reenter password"), 'passwd2'); $password2->setIsPassword(true); +$password2->setSameValueFieldID('passwd1'); $securitySettingsContent->addElement($password1, true); $securitySettingsContent->addElement($password2, true); $securitySettings = new htmlFieldset($securitySettingsContent, _("Security settings"), '../../graphics/security.png'); diff --git a/lam/templates/config/mainmanage.php b/lam/templates/config/mainmanage.php index e58c09ca..23c07fba 100644 --- a/lam/templates/config/mainmanage.php +++ b/lam/templates/config/mainmanage.php @@ -458,6 +458,7 @@ $pwd1->setIsPassword(true); $passwordTable->addElement($pwd1, true); $pwd2 = new htmlTableExtendedInputField(_("Reenter password"), 'masterpassword2', ''); $pwd2->setIsPassword(true); +$pwd2->setSameValueFieldID('masterpassword'); $passwordTable->addElement($pwd2, true); $container->addElement($passwordTable, true); $container->addElement(new htmlSpacer(null, '20px'), true); diff --git a/lam/templates/config/profmanage.php b/lam/templates/config/profmanage.php index ab2bd2d7..2d9953d2 100644 --- a/lam/templates/config/profmanage.php +++ b/lam/templates/config/profmanage.php @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2003 - 2013 Roland Gruber + Copyright (C) 2003 - 2014 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 @@ -247,6 +247,7 @@ $container->addElement($profileNewPwd1, true); $profileNewPwd2 = new htmlTableExtendedInputField(_("Reenter password"), 'addpassword2'); $profileNewPwd2->setIsPassword(true); $profileNewPwd2->setFieldSize(15); +$profileNewPwd2->setSameValueFieldID('addpassword'); $container->addElement($profileNewPwd2, true); $newProfileButton = new htmlButton('btnAddProfile', _('Add')); $newProfileButton->setOnClick("jQuery('#action').val('add');showConfirmationDialog('" . _("Add profile") . "', '" . @@ -285,6 +286,7 @@ $container->addElement($profileSetPwd1, true); $profileSetPwd2 = new htmlTableExtendedInputField(_("Reenter password"), 'setpassword2'); $profileSetPwd2->setIsPassword(true); $profileSetPwd2->setFieldSize(15); +$profileSetPwd2->setSameValueFieldID('setpassword'); $container->addElement($profileSetPwd2, true); $setPasswordProfileButton = new htmlButton('btnSetPasswordProfile', _('Set profile password')); $setPasswordProfileButton->setOnClick("jQuery('#action').val('setpass');showConfirmationDialog('" . _("Set profile password") . "', '" . diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index c6eb19e8..8461fc3a 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2003 - 2013 Roland Gruber + Copyright (C) 2003 - 2014 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 @@ -476,7 +476,7 @@ function bindShowNewZoneDialog(title, okText, cancelText) { } - +// creates the tooltips for help buttons jQuery(document).ready( function() { jQuery(document).tooltip({ @@ -493,3 +493,36 @@ jQuery(document).ready( }) } ); + +/** + * Checks if the given field has the same value as the reference field. + * Field is marked red if different and green if equal. + * + * @param fieldID ID of field to check + * @param fieldIDReference ID of reference field + */ +function checkFieldsHaveSameValues(fieldID, fieldIDReference) { + var field = jQuery('#' + fieldID); + var fieldRef = jQuery('#' + fieldIDReference); + var check = + function() { + var value = field.val(); + var valueRef = fieldRef.val(); + if ((value == '') && (valueRef == '')) { + field.removeClass('markFail'); + field.removeClass('markOk'); + } + else { + if (value == valueRef) { + field.removeClass('markFail'); + field.addClass('markOk'); + } + else { + field.addClass('markFail'); + field.removeClass('markOk'); + } + } + } + jQuery(field).keyup(check); + jQuery(fieldRef).keyup(check); +}