From a6858c6a90527664406b82e32fcf457628700df1 Mon Sep 17 00:00:00 2001 From: chris <chris@jalakai.co.uk> Date: Wed, 23 Aug 2006 13:56:26 +0200 Subject: [PATCH] user manager update - add capability to send notification emails to users on creation and password modification (bug#640) - add success and fail messages for new user addition - fix bug when modification of username wasn't allowed, 'Edit user' fields weren't populated - fix (php5 only?) bug where default group wasn't given to a new user if no groups were specified - added explanatory notes concerning default group and password notification emails This patch adds several new strings to the plugin's lang.php darcs-hash:20060823115626-9b6ab-ea98ef630c79b28b52141957deb3efc307a9291d.gz --- lib/plugins/usermanager/admin.php | 74 ++++++++++++++++++++---- lib/plugins/usermanager/lang/en/lang.php | 7 +++ 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php index 16ef57c5f..1335c9ef1 100644 --- a/lib/plugins/usermanager/admin.php +++ b/lib/plugins/usermanager/admin.php @@ -30,7 +30,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { var $_last = 0; // index of the last user to be displayed var $_pagesize = 20; // number of users to list on one page var $_edit_user = ''; // set to user selected for editing - var $_edit_userdata = array(); + var $_edit_userdata = array(); var $_disabled = ''; // if disabled set to explanatory string /** @@ -254,12 +254,16 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { * @todo disable fields which the backend can't change */ function _htmlUserForm($cmd,$user='',$userdata=array(),$indent=0) { + global $conf; $name = $mail = $groups = ''; + $notes = array(); if ($user) { extract($userdata); if (!empty($grps)) $groups = join(',',$grps); + } else { + $notes[] = sprintf($this->lang['note_group'],$conf['defaultgroup']); } ptln("<form action=\"".wl($ID)."\" method=\"post\">",$indent); @@ -275,6 +279,14 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { $this->_htmlInputField($cmd."_usermail", "usermail", $this->lang["user_mail"], $mail, $this->_auth->canDo("modMail"), $indent+6); $this->_htmlInputField($cmd."_usergroups","usergroups",$this->lang["user_groups"],$groups,$this->_auth->canDo("modGroups"),$indent+6); + if ($this->_auth->canDo("modPass")) { + if ($user) { + $notes[] = $this->lang['note_notify']; + } + + ptln("<tr><td><label for=\"".$cmd."_usernotify\" >".$this->lang["user_notify"].": </label></td><td><input type=\"checkbox\" id=\"".$cmd."_usernotify\" name=\"usernotify\" value=\"1\" /></td></tr>", $indent); + } + ptln(" </tbody>",$indent); ptln(" <tbody>",$indent); ptln(" <tr>",$indent); @@ -293,6 +305,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { ptln(" </tr>",$indent); ptln(" </tbody>",$indent); ptln(" </table>",$indent); + + foreach ($notes as $note) + ptln("<div class=\"fn\">".$note."</div>",$indent); + ptln("</form>",$indent); } @@ -323,7 +339,18 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser(); if (empty($user)) return false; - return $this->_auth->createUser($user,$pass,$name,$mail,$grps); + if ($ok = $this->_auth->createUser($user,$pass,$name,$mail,$grps)) { + + msg($this->lang['add_ok'], 1); + + if (!empty($_REQUEST['usernotify']) && $pass) { + $this->_notifyUser($user,$pass); + } + } else { + msg($this->lang['add_fail'], 1); + } + + return $ok; } /** @@ -346,10 +373,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { $part2 = str_replace('%d', (count($selected)-$count), $this->lang['delete_fail']); msg("$part1, $part2",-1); } - - return true; + + return true; } - + /** * Edit user (a user has been selected for editing) */ @@ -396,7 +423,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { // check if $newuser already exists if ($this->_auth->getUserData($newuser)) { msg(sprintf($this->lang['update_exists'],$newuser),-1); - $this->_edit_user = $olduser; + $re_edit = true; } else { $changes['user'] = $newuser; } @@ -411,18 +438,43 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { if (!empty($newgrps) && $this->_auth->canDo('modGroups') && $newgrps != $oldinfo['grps']) $changes['grps'] = $newgrps; - if ($this->_auth->modifyUser($olduser, $changes)) { + if ($ok = $this->_auth->modifyUser($olduser, $changes)) { msg($this->lang['update_ok'],1); + + if (!empty($_REQUEST['usernotify']) && $newpass) { + $notify = empty($changes['user']) ? $olduser : $newuser; + $this->_notifyUser($notify,$newpass); + } + } else { msg($this->lang['update_fail'],-1); } - return true; + if (!empty($re_edit)) { + $this->_editUser($olduser); + } + + return $ok; } - /* + /** + * send password change notification email + */ + function _notifyUser($user, $password) { + + if ($sent = auth_sendPassword($user,$password)) { + msg($this->lang['notify_ok'], 1); + } else { + msg($this->lang['notify_fail'], -1); + } + + return $sent; + } + + /** * retrieve & clean user data from the form - * return an array(user, password, full name, email, array(groups)) + * + * @return array(user, password, full name, email, array(groups)) */ function _retrieveUser($clean=true) { @@ -432,7 +484,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { $user[3] = $_REQUEST['usermail']; $user[4] = preg_split('/\s*,\s*/',$_REQUEST['usergroups'],-1,PREG_SPLIT_NO_EMPTY); - if (is_array($user[4]) && (count($user[4]) == 1) && (trim($user[4][0]) == '')) { + if (empty($user[4]) || (is_array($user[4]) && (count($user[4]) == 1) && (trim($user[4][0]) == ''))) { $user[4] = null; } diff --git a/lib/plugins/usermanager/lang/en/lang.php b/lib/plugins/usermanager/lang/en/lang.php index 2511898e9..50c65ff1c 100644 --- a/lib/plugins/usermanager/lang/en/lang.php +++ b/lib/plugins/usermanager/lang/en/lang.php @@ -47,4 +47,11 @@ $lang['last'] = 'last'; // added after 2006-03-09 release $lang['edit_usermissing'] = 'Selected user not found, the specified user name may have been deleted or changed elsewhere.'; +$lang['user_notify'] = 'Notify user'; +$lang['note_notify'] = 'Notification emails are only sent if the user is given a new password.'; +$lang['note_group'] = 'New users will be added to the default group (%s) if no group is specified.'; +$lang['add_ok'] = 'User added successfully'; +$lang['add_fail'] = 'User addition failed'; +$lang['notify_ok'] = 'Notification email sent'; +$lang['notify_fail'] = 'Notification email could not be sent'; -- GitLab