From 1f49f941f6920b47b25510618a24481ec8bbf1f3 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 24 Mar 2013 19:18:15 +0000 Subject: [PATCH] allow to send password mail to alternate recipient --- lam/help/help.inc | 2 ++ lam/lib/account.inc | 6 +++++- lam/lib/modules.inc | 19 ++++++++++++++++--- lam/templates/lib/500_lam.js | 4 +++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lam/help/help.inc b/lam/help/help.inc index 0692813c..9f7bb7c8 100644 --- a/lam/help/help.inc +++ b/lam/help/help.inc @@ -185,6 +185,8 @@ $helpArray = array ( "Text" => _("Here you can import PDF structures from other server profiles (overwrite existing).")), "409" => array ("Headline" => _("Export PDF structure"), "Text" => _("Here you can export PDF structures to other server profiles (overwrite existing). You may also export a structure to the global templates. In this case it will always be copied to all server profiles that do not yet have a structure with this name.")), + "410" => array ("Headline" => _("Alternate recipient"), + "Text" => _("Here you can enter an alternative mail address for the password. To use the user's primary email address please leave the field blank.")), // 500 - 599 // LAM Pro "501" => array ("Headline" => _("LDAP suffix"), diff --git a/lam/lib/account.inc b/lam/lib/account.inc index fe83ed5e..97b3d878 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -888,12 +888,16 @@ function extractDNSuffix($dn) { * * @param String $pwd new password * @param array $user LDAP attributes of user + * @param String $recipient recipient address (optional, $user['mail'][0] used by default) * @return array list of arrays that can be used to create status messages */ -function sendPasswordMail($pwd, $user) { +function sendPasswordMail($pwd, $user, $recipient = null) { $user = array_change_key_case($user, CASE_LOWER); // read mail data $mailTo = $user['mail'][0]; + if (!empty($recipient)) { + $mailTo = $recipient; + } $mailFrom = $_SESSION['config']->getLamProMailFrom(); $mailReplyTo = $_SESSION['config']->getLamProMailReplyTo(); $mailSubject = $_SESSION['config']->getLamProMailSubject(); diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 4d03a015..1d84d40b 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -748,6 +748,8 @@ class accountContainer { private $titleBarSubtitle = null; /** send password via mail */ private $sendPasswordViaMail = null; + /** send password via mail to this alternate address */ + private $sendPasswordViaMailAlternateAddress = null; /** * Returns the account module with the given class name @@ -1040,8 +1042,11 @@ class accountContainer { $container->addElement(new htmlHelpLink('406'), true); } if (isLAMProVersion() && isset($this->attributes_orig['mail'][0])) { - $container->addElement(new htmlTableExtendedInputCheckbox('lamPasswordChangeSendMail', false, _('Send via mail'))); + $pwdMailCheckbox = new htmlTableExtendedInputCheckbox('lamPasswordChangeSendMail', false, _('Send via mail')); + $pwdMailCheckbox->setTableRowsToShow(array('lamPasswordChangeSendMailAddress')); + $container->addElement($pwdMailCheckbox); $container->addElement(new htmlHelpLink('407'), true); + $container->addElement(new htmlTableExtendedInputField(_('Alternate recipient'), 'lamPasswordChangeSendMailAddress', '', '410')); } $container->addElement(new htmlSpacer(null, '10px'), true); // password modules @@ -1134,6 +1139,13 @@ class accountContainer { } if (isLAMProVersion() && $sendMail) { $this->sendPasswordViaMail = $password1; + if (!empty($input['sendMailAlternateAddress'])) { + if (!get_preg($input['sendMailAlternateAddress'], 'email')) { + $return['messages'] .= StatusMessage('ERROR', _('Alternate recipient'), _('Please enter a valid email address!'), array(), true); + $return['errorsOccured'] = 'true'; + } + $this->sendPasswordViaMailAlternateAddress = $input['sendMailAlternateAddress']; + } } if ($return['errorsOccured'] == 'false') { $return['messages'] .= StatusMessage('INFO', _('The new password will be stored in the directory after you save this account.'), '', array(), true); @@ -1780,7 +1792,7 @@ class accountContainer { for ($i=0; $iserver(), $DNs[$i], $attributes[$DNs[$i]]['modify']); if (!$success) { @@ -1825,11 +1837,12 @@ class accountContainer { } // send password mail if (!$stopprocessing && isLAMProVersion() && ($this->sendPasswordViaMail != null)) { - $mailMessages = sendPasswordMail($this->sendPasswordViaMail, $prePostModifyAttributes); + $mailMessages = sendPasswordMail($this->sendPasswordViaMail, $prePostModifyAttributes, $this->sendPasswordViaMailAlternateAddress); if (sizeof($mailMessages) > 0) { $errors = array_merge($errors, $mailMessages); } $this->sendPasswordViaMail = null; + $this->sendPasswordViaMailAlternateAddress = null; } if (!$stopprocessing) { // post modify actions diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index 33650fe1..5543e869 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -248,13 +248,15 @@ function passwordHandleInput(random, ajaxURL) { var pwd2 = jQuery('#passwordDialog').find('[name=newPassword2]').val(); var forcePasswordChange = jQuery('input[name=lamForcePasswordChange]').prop('checked'); var sendMail = jQuery('input[name=lamPasswordChangeSendMail]').prop('checked'); + var sendMailAlternateAddress = jQuery('#passwordDialog').find('[name=lamPasswordChangeSendMailAddress]').val(); var pwdJSON = { "modules": modules, "password1": pwd1, "password2": pwd2, "random": random, "forcePasswordChange": forcePasswordChange, - "sendMail": sendMail + "sendMail": sendMail, + "sendMailAlternateAddress": sendMailAlternateAddress }; // make AJAX call jQuery.post(ajaxURL, {jsonInput: pwdJSON}, function(data) {passwordHandleReply(data);}, 'json');