allow to send password mails on user edit page
This commit is contained in:
parent
59f1829e60
commit
1f52edb550
|
@ -6,6 +6,7 @@ June 2012
|
|||
-> Separate group of names module for users allows to manage memberships if Unix module is not used (RFE 3504429)
|
||||
-> Named object module for groups (used for rfc2307bis schema)
|
||||
-> Password change page allows account (un)locking
|
||||
-> Allow to send password mails on user edit page
|
||||
- fixed bugs
|
||||
-> Asterisk extensions with same name (3528288)
|
||||
|
||||
|
|
|
@ -169,6 +169,8 @@ $helpArray = array (
|
|||
"Text" => _("The PDF structure defines what information is exported as PDF file and how the pages are structured. You can manage the PDF structures in the PDF editor (under \"Tools\").")),
|
||||
"406" => array ("Headline" => _("Force password change"),
|
||||
"Text" => _("If you set this option then the user has to change his password at the next login.")),
|
||||
"407" => array ("Headline" => _("Send via mail"),
|
||||
"Text" => _("Sends the password to the user via mail. Please edit your LAM server profile to setup the mail settings.")),
|
||||
// 500 - 599
|
||||
// LAM Pro
|
||||
"501" => array ("Headline" => _("LDAP suffix"),
|
||||
|
|
|
@ -4,7 +4,7 @@ $Id$
|
|||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2003 - 2006 Tilo Lutz
|
||||
2009 - 2011 Roland Gruber
|
||||
2009 - 2012 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
|
||||
|
@ -848,4 +848,62 @@ function extractDNSuffix($dn) {
|
|||
return substr($dn, strpos($dn, ',')+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the password mail.
|
||||
*
|
||||
* @param String $pwd new password
|
||||
* @param array $user LDAP attributes of user
|
||||
* @return array list of arrays that can be used to create status messages
|
||||
*/
|
||||
function sendPasswordMail($pwd, $user) {
|
||||
// read mail data
|
||||
$mailTo = $user['mail'][0];
|
||||
$mailFrom = $_SESSION['config']->getLamProMailFrom();
|
||||
$mailReplyTo = $_SESSION['config']->getLamProMailReplyTo();
|
||||
$mailSubject = $_SESSION['config']->getLamProMailSubject();
|
||||
$mailText = $_SESSION['config']->getLamProMailText();
|
||||
$mailIsHTML = $_SESSION['config']->getLamProMailIsHTML();
|
||||
$subject = $mailSubject;
|
||||
$body = $mailText;
|
||||
$body = str_replace('@@newPassword@@', $pwd, $body);
|
||||
$results = array();
|
||||
$found = preg_match('/\@\@[^\@]+\@\@/', $body, $results);
|
||||
while ($found == 1) {
|
||||
$attr = str_replace('@', '', $results[0]);
|
||||
$value = '';
|
||||
if (isset($user[strtolower($attr)][0])) {
|
||||
$value = $user[strtolower($attr)][0];
|
||||
}
|
||||
$body = str_replace('@@' . $attr . '@@', $value, $body);
|
||||
$found = preg_match('/\@\@[^\@]+\@\@/', $body, $results);
|
||||
}
|
||||
$headerLines = "X-Mailer: LDAP Account Manager\r\n";
|
||||
if ($mailFrom != '') {
|
||||
$headerLines .= 'From: ' . $mailFrom . "\r\n";
|
||||
}
|
||||
if ($mailReplyTo != '') {
|
||||
$headerLines .= 'Reply-To: ' . $mailReplyTo . "\r\n";
|
||||
}
|
||||
if ($mailIsHTML == 'true') {
|
||||
$headerLines .= "MIME-Version: 1.0\r\n";
|
||||
$headerLines .= "Content-type: text/html; charset=UTF-8\r\n";
|
||||
}
|
||||
else {
|
||||
$headerLines .= "Content-type: text; charset=UTF-8\r\n";
|
||||
}
|
||||
$success = mail($mailTo, $subject, $body, $headerLines);
|
||||
if ($success) {
|
||||
logNewMessage(LOG_DEBUG, 'Sent password mail to ' . $mailTo);
|
||||
return array(
|
||||
array('INFO', sprintf(_('Mail successfully sent to %s.'), htmlspecialchars($mailTo)))
|
||||
);
|
||||
}
|
||||
else {
|
||||
logNewMessage(LOG_ERR, 'Unable to send password mail to ' . htmlspecialchars($mailTo));
|
||||
return array(
|
||||
array('ERROR', _('Unable to send mail!'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1004,6 +1004,10 @@ class accountContainer {
|
|||
$container->addElement(new htmlTableExtendedInputCheckbox('lamForcePasswordChange', false, _('Force password change')));
|
||||
$container->addElement(new htmlHelpLink('406'), true);
|
||||
}
|
||||
if (isLAMProVersion() && isset($this->attributes_orig['mail'][0])) {
|
||||
$container->addElement(new htmlTableExtendedInputCheckbox('lamPasswordChangeSendMail', false, _('Send via mail')));
|
||||
$container->addElement(new htmlHelpLink('407'), true);
|
||||
}
|
||||
$container->addElement(new htmlSpacer(null, '10px'), true);
|
||||
// password modules
|
||||
$moduleContainer = new htmlTable();
|
||||
|
@ -1067,6 +1071,10 @@ class accountContainer {
|
|||
if (isset($input['forcePasswordChange']) && ($input['forcePasswordChange'] == 'true')) {
|
||||
$forcePasswordChange = true;
|
||||
}
|
||||
$sendMail = false;
|
||||
if (isset($input['sendMail']) && ($input['sendMail'] == 'true')) {
|
||||
$sendMail = true;
|
||||
}
|
||||
$return['forcePasswordChange'] = $forcePasswordChange;
|
||||
if ($return['errorsOccured'] == 'false') {
|
||||
// set new password
|
||||
|
@ -1090,6 +1098,22 @@ class accountContainer {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (isLAMProVersion() && $sendMail) {
|
||||
$mailMessages = sendPasswordMail($password1, $this->attributes_orig);
|
||||
if (sizeof($mailMessages) > 0) {
|
||||
for ($i = 0; $i < sizeof($mailMessages); $i++) {
|
||||
if ($mailMessages[$i][0] == 'ERROR') {
|
||||
$return['errorsOccured'] = 'true';
|
||||
}
|
||||
if (sizeof($mailMessages[$i]) == 2) {
|
||||
$return['messages'] .= StatusMessage($mailMessages[$i][0], $mailMessages[$i][1], '', array(), true);
|
||||
}
|
||||
elseif (sizeof($mailMessages[$i]) == 3) {
|
||||
$return['messages'] .= StatusMessage($mailMessages[$i][0], $mailMessages[$i][1], $mailMessages[$i][2], array(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($return['errorsOccured'] == 'false') {
|
||||
$return['messages'] .= StatusMessage('INFO', _('The new password will be stored in the directory after you save this account.'), '', array(), true);
|
||||
}
|
||||
|
|
|
@ -271,12 +271,14 @@ function passwordHandleInput(random, ajaxURL) {
|
|||
var pwd1 = jQuery('#passwordDialog').find('[name=newPassword1]').val();
|
||||
var pwd2 = jQuery('#passwordDialog').find('[name=newPassword2]').val();
|
||||
var forcePasswordChange = jQuery('input[name=lamForcePasswordChange]').attr('checked');
|
||||
var sendMail = jQuery('input[name=lamPasswordChangeSendMail]').attr('checked');
|
||||
var pwdJSON = {
|
||||
"modules": modules,
|
||||
"password1": pwd1,
|
||||
"password2": pwd2,
|
||||
"random": random,
|
||||
"forcePasswordChange": forcePasswordChange
|
||||
"forcePasswordChange": forcePasswordChange,
|
||||
"sendMail": sendMail
|
||||
};
|
||||
// make AJAX call
|
||||
jQuery.post(ajaxURL, {jsonInput: pwdJSON}, function(data) {passwordHandleReply(data);}, 'json');
|
||||
|
|
Loading…
Reference in New Issue