use AJAX for password change dialog
This commit is contained in:
parent
6bf37c61da
commit
38a10674ef
|
@ -753,26 +753,6 @@ class accountContainer {
|
||||||
if (isset($_POST['accountContainerReset'])) {
|
if (isset($_POST['accountContainerReset'])) {
|
||||||
$result = $this->load_account($this->dn_orig);
|
$result = $this->load_account($this->dn_orig);
|
||||||
}
|
}
|
||||||
elseif (isset($_POST['setNewPasswordCancel'])) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
elseif (isset($_POST['setNewPasswordOk']) || isset($_POST['setNewPasswordRandom'])) {
|
|
||||||
$pwdMessages = $this->setNewPassword();
|
|
||||||
$pwdErrors = 0;
|
|
||||||
for ($i = 0; $i < sizeof($pwdMessages); $i++) {
|
|
||||||
if ($pwdMessages[$i][0] == 'ERROR') {
|
|
||||||
$pwdErrors++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($pwdErrors == 0) {
|
|
||||||
$result[] = array('INFO', _('The new password will be stored in the directory after you save this account.'));
|
|
||||||
$result = array_merge($result, $pwdMessages);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->printPasswordPromt($pwdMessages);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif (!$profileLoaded) {
|
elseif (!$profileLoaded) {
|
||||||
// change dn suffix
|
// change dn suffix
|
||||||
if (isset($_GET['suffix']) && ($_GET['suffix'] != '') && ($this->dn == null)) {
|
if (isset($_GET['suffix']) && ($_GET['suffix'] != '') && ($this->dn == null)) {
|
||||||
|
@ -887,11 +867,6 @@ class accountContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check if password change was requested
|
|
||||||
if (!$errorsOccured && isset($_POST['accountContainerSetPassword'])) {
|
|
||||||
$this->printPasswordPromt(array());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// prints a module content page
|
// prints a module content page
|
||||||
$this->printModuleContent($result, $stopProcessing);
|
$this->printModuleContent($result, $stopProcessing);
|
||||||
}
|
}
|
||||||
|
@ -904,6 +879,7 @@ class accountContainer {
|
||||||
*/
|
*/
|
||||||
private function printModuleContent($result, $stopProcessing) {
|
private function printModuleContent($result, $stopProcessing) {
|
||||||
$this->printPageHeader();
|
$this->printPageHeader();
|
||||||
|
$this->printPasswordPromt();
|
||||||
// display error messages
|
// display error messages
|
||||||
if (is_array($result)) {
|
if (is_array($result)) {
|
||||||
for ($i=0; $i<sizeof($result); $i++) {
|
for ($i=0; $i<sizeof($result); $i++) {
|
||||||
|
@ -914,6 +890,7 @@ class accountContainer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
echo '<div id="passwordMessageArea"></div>';
|
||||||
echo "<table class=\"".$this->type."list-bright\" border=0 width=\"100%\" style=\"border-collapse: collapse;\">\n";
|
echo "<table class=\"".$this->type."list-bright\" border=0 width=\"100%\" style=\"border-collapse: collapse;\">\n";
|
||||||
if (checkIfWriteAccessIsAllowed()) {
|
if (checkIfWriteAccessIsAllowed()) {
|
||||||
echo "<tr class=\"".$this->type."list-bright\"><td style=\"padding: 15px 15px 0px 15px;\">\n";
|
echo "<tr class=\"".$this->type."list-bright\"><td style=\"padding: 15px 15px 0px 15px;\">\n";
|
||||||
|
@ -984,25 +961,11 @@ class accountContainer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints the input fields of the central password service.
|
* Prints the input fields of the central password service.
|
||||||
*
|
|
||||||
* @param $errors list of error messages
|
|
||||||
*/
|
*/
|
||||||
private function printPasswordPromt($errors) {
|
private function printPasswordPromt() {
|
||||||
$this->printPageHeader();
|
echo "<div id=\"passwordDialog\" class=\"hidden\">\n";
|
||||||
echo "<div class=\"" . $this->type . "list-bright smallPaddingContent\">\n";
|
echo '<div id="passwordDialogMessageArea"></div>';
|
||||||
$container = new htmlTable();
|
$container = new htmlTable();
|
||||||
// title
|
|
||||||
$container->addElement(new htmlSubTitle(_("Set password")), true);
|
|
||||||
// error messages
|
|
||||||
for ($i = 0; $i < sizeof($errors); $i++) {
|
|
||||||
$text = '';
|
|
||||||
if (isset($errors[$i][2])) $text = $errors[$i][2];
|
|
||||||
$params = array();
|
|
||||||
if (isset($errors[$i][3])) $params = $errors[$i][3];
|
|
||||||
$message = new htmlStatusMessage($errors[$i][0], $errors[$i][1], $text, $params);
|
|
||||||
$message->colspan = 3;
|
|
||||||
$container->addElement($message, true);
|
|
||||||
}
|
|
||||||
// password fields
|
// password fields
|
||||||
$container->addElement(new htmlOutputText(_('Password')));
|
$container->addElement(new htmlOutputText(_('Password')));
|
||||||
$pwdInput1 = new htmlInputField('newPassword1');
|
$pwdInput1 = new htmlInputField('newPassword1');
|
||||||
|
@ -1018,7 +981,7 @@ class accountContainer {
|
||||||
$moduleContainer = new htmlTable();
|
$moduleContainer = new htmlTable();
|
||||||
foreach ($this->module as $name => $module) {
|
foreach ($this->module as $name => $module) {
|
||||||
if (($module instanceof passwordService) && $module->managesPasswordAttributes()) {
|
if (($module instanceof passwordService) && $module->managesPasswordAttributes()) {
|
||||||
$moduleContainer->addElement(new htmlInputCheckbox('cb_' . $name, true));
|
$moduleContainer->addElement(new htmlInputCheckbox('password_cb_' . $name, true));
|
||||||
$buttonImage = $module->getIcon();
|
$buttonImage = $module->getIcon();
|
||||||
if ($buttonImage != null) {
|
if ($buttonImage != null) {
|
||||||
$moduleContainer->addElement(new htmlImage('../../graphics/' . $buttonImage, null, null, getModuleAlias($name, $this->type)));
|
$moduleContainer->addElement(new htmlImage('../../graphics/' . $buttonImage, null, null, getModuleAlias($name, $this->type)));
|
||||||
|
@ -1030,63 +993,70 @@ class accountContainer {
|
||||||
$moduleContainer->colspan = 5;
|
$moduleContainer->colspan = 5;
|
||||||
$container->addElement($moduleContainer, true);
|
$container->addElement($moduleContainer, true);
|
||||||
$container->addElement(new htmlSpacer(null, '10px'), true);
|
$container->addElement(new htmlSpacer(null, '10px'), true);
|
||||||
// buttons
|
|
||||||
$buttonContainer = new htmlTable();
|
|
||||||
$buttonContainer->colspan = 3;
|
|
||||||
$buttonContainer->addElement(new htmlButton('setNewPasswordOk', _('Ok')));
|
|
||||||
$buttonContainer->addElement(new htmlButton('setNewPasswordCancel', _('Cancel')));
|
|
||||||
$buttonContainer->addElement(new htmlButton('setNewPasswordRandom', _('Set random password')));
|
|
||||||
$container->addElement($buttonContainer);
|
|
||||||
// generate HTML
|
// generate HTML
|
||||||
$tabindex = 1;
|
$tabindex = 2000;
|
||||||
parseHtml(null, $container, array(), false, $tabindex, $this->type);
|
parseHtml(null, $container, array(), false, $tabindex, $this->type);
|
||||||
// set focus on password field
|
|
||||||
echo "<script type=\"text/javascript\" language=\"javascript\">\n";
|
|
||||||
echo "<!--\n";
|
|
||||||
echo "myElement = document.getElementsByName('newPassword1')[0];\n";
|
|
||||||
echo "myElement.focus();\n";
|
|
||||||
echo "//-->\n";
|
|
||||||
echo "</script>\n";
|
|
||||||
echo "</div>\n";
|
echo "</div>\n";
|
||||||
$this->printPageFooter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the new password in all selected account modules.
|
* Sets the new password in all selected account modules.
|
||||||
*
|
*
|
||||||
* @return array list of messages
|
* @param array $input input parameters
|
||||||
*/
|
*/
|
||||||
private function setNewPassword() {
|
public function setNewPassword($input) {
|
||||||
$return = array();
|
$password1 = $input['password1'];
|
||||||
if (isset($_POST['setNewPasswordRandom'])) {
|
$password2 = $input['password2'];
|
||||||
$_POST['newPassword1'] = generateRandomPassword();
|
$random = $input['random'];
|
||||||
$return[] = array('INFO', _('The password was set to:') . ' ' . $_POST['newPassword1']);
|
$modules = $input['modules'];
|
||||||
|
for ($m = 0; $m < sizeof($modules); $m++) {
|
||||||
|
$modules[$m] = str_replace('password_cb_', '', $modules[$m]);
|
||||||
|
}
|
||||||
|
$return = array(
|
||||||
|
'messages' => '',
|
||||||
|
'errorsOccured' => 'false'
|
||||||
|
);
|
||||||
|
if ($random == 'true') {
|
||||||
|
$password1 = generateRandomPassword();
|
||||||
|
$return['messages'] .= StatusMessage('INFO', _('The password was set to:') . ' ' . $password1, '', array(), true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// check if passwords match
|
// check if passwords match
|
||||||
if ($_POST['newPassword1'] != $_POST['newPassword2']) {
|
if ($password1 != $password2) {
|
||||||
$return[] = array('ERROR', _('Passwords are different!'));
|
$return['messages'] .= StatusMessage('ERROR', _('Passwords are different!'), '', array(), true);
|
||||||
return $return;
|
$return['errorsOccured'] = 'true';
|
||||||
}
|
}
|
||||||
// check passsword stregth
|
// check passsword stregth
|
||||||
$pwdPolicyResult = checkPasswordStrength($_POST['newPassword1']);
|
$pwdPolicyResult = checkPasswordStrength($password1);
|
||||||
if ($pwdPolicyResult !== true) {
|
if ($pwdPolicyResult !== true) {
|
||||||
$return[] = array('ERROR', $pwdPolicyResult);
|
$return['messages'] .= StatusMessage('ERROR', $pwdPolicyResult, '', array(), true);
|
||||||
return $return;
|
$return['errorsOccured'] = 'true';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set new password
|
if ($return['errorsOccured'] == 'false') {
|
||||||
$selectedModules = array();
|
// set new password
|
||||||
foreach ($_POST as $key => $value) {
|
foreach ($this->module as $name => $module) {
|
||||||
if (substr($key, 0, 3) == 'cb_') {
|
if ($module instanceof passwordService) {
|
||||||
$name = substr($key, 3);
|
$messages = $module->passwordChangeRequested($password1, $modules);
|
||||||
$selectedModules[] = $name;
|
for ($m = 0; $m < sizeof($messages); $m++) {
|
||||||
|
if ($messages[$m][0] == 'ERROR') {
|
||||||
|
$return['errorsOccured'] = 'true';
|
||||||
|
}
|
||||||
|
if (sizeof($messages[$m]) == 2) {
|
||||||
|
$return['messages'] .= StatusMessage($messages[$m][0], $messages[$m][1], '', array(), true);
|
||||||
|
}
|
||||||
|
elseif (sizeof($messages[$m]) == 3) {
|
||||||
|
$return['messages'] .= StatusMessage($messages[$m][0], $messages[$m][1], $messages[$m][2], array(), true);
|
||||||
|
}
|
||||||
|
elseif (sizeof($messages[$m]) == 4) {
|
||||||
|
$return['messages'] .= StatusMessage($messages[$m][0], $messages[$m][1], $messages[$m][2], $messages[$m][2], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($this->module as $name => $module) {
|
if ($return['errorsOccured'] == 'false') {
|
||||||
if ($module instanceof passwordService) {
|
$return['messages'] .= StatusMessage('INFO', _('The new password will be stored in the directory after you save this account.'), '', array(), true);
|
||||||
$return = array_merge($return, $module->passwordChangeRequested($_POST['newPassword1'], $selectedModules));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -1106,7 +1076,8 @@ class accountContainer {
|
||||||
}
|
}
|
||||||
if ($this->showSetPasswordButton()) {
|
if ($this->showSetPasswordButton()) {
|
||||||
echo " ";
|
echo " ";
|
||||||
echo "<button id=\"modPasswordButton\" name=\"accountContainerSetPassword\">" . _('Set password') . "</button> \n";
|
echo '<a href="#" onclick="passwordShowChangeDialog(\'' . _('Set password') . '\', \'' . _('Ok') . '\', \''
|
||||||
|
. _('Cancel') . '\', \'' . _('Set random password') . '\', \'../misc/ajax.php?function=passwordChange\');" id="modPasswordButton">' . _('Set password') . "</a> \n";
|
||||||
}
|
}
|
||||||
echo "</td>";
|
echo "</td>";
|
||||||
echo "<td align=\"right\">";
|
echo "<td align=\"right\">";
|
||||||
|
|
|
@ -72,7 +72,7 @@ function listResizeITabContentDiv() {
|
||||||
var myDiv = document.getElementById("listTabContentArea");
|
var myDiv = document.getElementById("listTabContentArea");
|
||||||
var height = document.documentElement.clientHeight;
|
var height = document.documentElement.clientHeight;
|
||||||
height -= myDiv.offsetTop;
|
height -= myDiv.offsetTop;
|
||||||
height -= 105
|
height -= 105;
|
||||||
myDiv.style.height = height +"px";
|
myDiv.style.height = height +"px";
|
||||||
|
|
||||||
var myDivScroll = document.getElementById("listScrollArea");
|
var myDivScroll = document.getElementById("listScrollArea");
|
||||||
|
@ -214,3 +214,71 @@ function automountShowNewMapDialog(title, okText, cancelText) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the dialog to change the password.
|
||||||
|
*
|
||||||
|
* @param title dialog title
|
||||||
|
* @param okText text for Ok button
|
||||||
|
* @param cancelText text for Cancel button
|
||||||
|
* @param randomText text for random password
|
||||||
|
* @param ajaxURL URL used for AJAX request
|
||||||
|
*/
|
||||||
|
function passwordShowChangeDialog(title, okText, cancelText, randomText, ajaxURL) {
|
||||||
|
var buttonList = {};
|
||||||
|
buttonList[randomText] = function() { passwordHandleInput("true", ajaxURL); };
|
||||||
|
buttonList[cancelText] = function() {
|
||||||
|
jQuery('#passwordDialogMessageArea').html("");
|
||||||
|
jQuery(this).dialog("close");
|
||||||
|
};
|
||||||
|
buttonList[okText] = function() { passwordHandleInput("false", ajaxURL); };
|
||||||
|
jQuery('#passwordDialog').dialog({
|
||||||
|
modal: true,
|
||||||
|
title: title,
|
||||||
|
dialogClass: 'defaultBackground',
|
||||||
|
buttons: buttonList,
|
||||||
|
width: 'auto'
|
||||||
|
});
|
||||||
|
// set focus on password field
|
||||||
|
var myElement = document.getElementsByName('newPassword1')[0];
|
||||||
|
myElement.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the password change when a button is pressed.
|
||||||
|
*
|
||||||
|
* @param random "true" if random password should be generated
|
||||||
|
* @param ajaxURL URL used for AJAX request
|
||||||
|
*/
|
||||||
|
function passwordHandleInput(random, ajaxURL) {
|
||||||
|
// get input values
|
||||||
|
var modules = new Array();
|
||||||
|
jQuery('#passwordDialog').find(':checked').each(function() {
|
||||||
|
modules.push(jQuery(this).attr('name'));
|
||||||
|
});
|
||||||
|
var pwd1 = jQuery('#passwordDialog').find('[name=newPassword1]').val();
|
||||||
|
var pwd2 = jQuery('#passwordDialog').find('[name=newPassword2]').val();
|
||||||
|
var pwdJSON = {
|
||||||
|
"modules": modules,
|
||||||
|
"password1": pwd1,
|
||||||
|
"password2": pwd2,
|
||||||
|
"random": random
|
||||||
|
};
|
||||||
|
// make AJAX call
|
||||||
|
jQuery.post(ajaxURL, {jsonInput: pwdJSON}, function(data) {passwordHandleReply(data);}, 'json');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages the server reply to a password change request.
|
||||||
|
*
|
||||||
|
* @param data JSON reply
|
||||||
|
*/
|
||||||
|
function passwordHandleReply(data) {
|
||||||
|
if (data.errorsOccured == "false") {
|
||||||
|
jQuery('#passwordDialogMessageArea').html("");
|
||||||
|
jQuery('#passwordDialog').dialog("close");
|
||||||
|
jQuery('#passwordMessageArea').html(data.messages);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jQuery('#passwordDialogMessageArea').html(data.messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
|
Copyright (C) 2011 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
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages all AJAX requests.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
* @package tools
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** security functions */
|
||||||
|
include_once("../../lib/security.inc");
|
||||||
|
|
||||||
|
// start session
|
||||||
|
startSecureSession();
|
||||||
|
|
||||||
|
lamAjax::handleRequest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages all AJAX requests.
|
||||||
|
*/
|
||||||
|
class lamAjax {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages an AJAX request.
|
||||||
|
*/
|
||||||
|
public static function handleRequest() {
|
||||||
|
if (!isset($_GET['function'])) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$function = $_GET['function'];
|
||||||
|
if (!isset($_POST['jsonInput'])) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$jsonInput = $_POST['jsonInput'];
|
||||||
|
|
||||||
|
if ($function == 'passwordChange') {
|
||||||
|
lamAjax::managePasswordChange($jsonInput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages a password change request on the edit account page.
|
||||||
|
*
|
||||||
|
* @param array $input input parameters
|
||||||
|
*/
|
||||||
|
public static function managePasswordChange($input) {
|
||||||
|
$return = $_SESSION['account']->setNewPassword($input);
|
||||||
|
echo json_encode($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue