From cb6e5946828e87a411f07d558d9e98a30c807998 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 24 Mar 2014 22:28:41 +0100 Subject: [PATCH] Adds possibility to send new password to users --- com.woltlab.wcf/clipboardAction.xml | 27 +++-- wcfsetup/install/files/acp/js/WCF.ACP.js | 62 +++++++++- .../install/files/acp/templates/userList.tpl | 13 ++- .../action/UserClipboardAction.class.php | 24 +++- .../worker/SendNewPasswordWorker.class.php | 109 ++++++++++++++++++ wcfsetup/install/lang/de.xml | 12 +- wcfsetup/install/lang/en.xml | 12 +- 7 files changed, 238 insertions(+), 21 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php diff --git a/com.woltlab.wcf/clipboardAction.xml b/com.woltlab.wcf/clipboardAction.xml index df5d5b74b1..f897023084 100644 --- a/com.woltlab.wcf/clipboardAction.xml +++ b/com.woltlab.wcf/clipboardAction.xml @@ -25,15 +25,23 @@ - - + + + 4 + + + + + + + 5 - + 6 @@ -41,16 +49,17 @@ - - - 4 + + + 7 - - - 5 + + + + 8 diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 66ef32bfaa..d581072bbd 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -9,7 +9,7 @@ /** * Initialize WCF.ACP namespace */ -WCF.ACP = {}; +WCF.ACP = { }; /** * Namespace for ACP application management. @@ -613,7 +613,7 @@ WCF.ACP.Package.Installation = Class.extend({ this._setIcon('spinner'); // collect form values - var $additionalData = {}; + var $additionalData = { }; $('#packageInstallationInnerContent input').each(function(index, inputElement) { var $inputElement = $(inputElement); var $type = $inputElement.attr('type'); @@ -677,7 +677,7 @@ WCF.ACP.Package.Installation = Class.extend({ * @param object additionalData */ _executeStep: function(step, node, additionalData) { - if (!additionalData) additionalData = {}; + if (!additionalData) additionalData = { }; var $data = $.extend({ node: node, @@ -1725,7 +1725,7 @@ WCF.ACP.Worker = Class.extend({ /** * Namespace for category-related functions. */ -WCF.ACP.Category = {}; +WCF.ACP.Category = { }; /** * Handles collapsing categories. @@ -1775,8 +1775,8 @@ WCF.ACP.Category.Collapsible = WCF.Collapsible.SimpleRemote.extend({ $('.collapsibleButton').remove(); // reinit containers - this._containers = {}; - this._containerData = {}; + this._containers = { }; + this._containerData = { }; var $containers = this._getContainers(); if ($containers.length == 0) { @@ -2101,6 +2101,56 @@ WCF.ACP.User.EnableHandler = { } }; +/** + * Handles the send new password clipboard action. + */ +WCF.ACP.User.SendNewPasswordHandler = { + /** + * action proxy + * @var WCF.Action.Proxy + */ + _proxy: null, + + /** + * Initializes WCF.ACP.User.SendNewPasswordHandler on first use. + */ + init: function() { + this._proxy = new WCF.Action.Proxy({ + success: $.proxy(this._success, this) + }); + + // bind clipboard event listener + $('.jsClipboardEditor').each($.proxy(function(index, container) { + var $container = $(container); + var $types = eval($container.data('types')); + if (WCF.inArray('com.woltlab.wcf.user', $types)) { + $container.on('clipboardAction', $.proxy(this._execute, this)); + return false; + } + }, this)); + }, + + /** + * Handles clipboard actions. + * + * @param object event + * @param string type + * @param string actionName + * @param object parameters + */ + _execute: function(event, type, actionName, parameters) { + if (actionName == 'com.woltlab.wcf.user.sendNewPassword') { + WCF.System.Confirmation.show(parameters.confirmMessage, function(action) { + if (action === 'confirm') { + new WCF.ACP.Worker('sendingNewPasswords', 'wcf\\system\\worker\\SendNewPasswordWorker', WCF.Language.get('wcf.acp.user.sendNewPassword.workerTitle'), { + userIDs: parameters.objectIDs + }); + } + }); + } + } +}; + /** * Namespace for import-related classes. */ diff --git a/wcfsetup/install/files/acp/templates/userList.tpl b/wcfsetup/install/files/acp/templates/userList.tpl index 2246eb450b..63e35de881 100644 --- a/wcfsetup/install/files/acp/templates/userList.tpl +++ b/wcfsetup/install/files/acp/templates/userList.tpl @@ -26,10 +26,19 @@ WCF.Language.addObject({ 'wcf.acp.user.banReason': '{lang}wcf.acp.user.banReason{/lang}', 'wcf.acp.user.banReason.description': '{lang}wcf.acp.user.banReason.description{/lang}', - 'wcf.acp.user.ban.sure': '{lang}wcf.acp.user.ban.sure{/lang}' + 'wcf.acp.user.ban.sure': '{lang}wcf.acp.user.ban.sure{/lang}', + 'wcf.acp.user.sendNewPassword.workerTitle': '{lang}wcf.acp.user.sendNewPassword.workerTitle{/lang}', + 'wcf.acp.worker.abort.confirmMessage': '{lang}wcf.acp.worker.abort.confirmMessage{/lang}' }); WCF.ACP.User.BanHandler.init(); - {if $__wcf->session->getPermission('admin.user.canEnableUser')}WCF.ACP.User.EnableHandler.init();{/if} + + {if $__wcf->session->getPermission('admin.user.canEnableUser')} + WCF.ACP.User.EnableHandler.init(); + {/if} + + {if $__wcf->session->getPermission('admin.user.canEditPassword')} + WCF.ACP.User.SendNewPasswordHandler.init(); + {/if} {event name='javascriptInit'} }); diff --git a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php index be41c6ef92..bf79d25c7b 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -25,7 +25,7 @@ class UserClipboardAction extends AbstractClipboardAction { /** * @see \wcf\system\clipboard\action\AbstractClipboardAction::$supportedActions */ - protected $supportedActions = array('assignToGroup', 'ban', 'delete', 'exportMailAddress', 'sendMail'); + protected $supportedActions = array('assignToGroup', 'ban', 'delete', 'exportMailAddress', 'sendMail', 'sendNewPassword'); /** * @see \wcf\system\clipboard\action\IClipboardAction::execute() @@ -56,6 +56,12 @@ class UserClipboardAction extends AbstractClipboardAction { case 'sendMail': $item->setURL(LinkHandler::getInstance()->getLink('UserMail')); break; + + case 'sendNewPassword': + $item->addParameter('confirmMessage', WCF::getLanguage()->getDynamicVariable('wcf.clipboard.item.com.woltlab.wcf.user.sendNewPassword.confirmMessage', array( + 'count' => $item->getCount() + ))); + break; } return $item; @@ -135,7 +141,7 @@ class UserClipboardAction extends AbstractClipboardAction { if (!isset($userToGroup[$row['userID']])) { $userToGroup[$row['userID']] = array(); } - + $userToGroup[$row['userID']][] = $row['groupID']; } @@ -148,4 +154,18 @@ class UserClipboardAction extends AbstractClipboardAction { return $userIDs; } + + /** + * Returns the ids of the users which can be sent new passwords. + * + * @return array + */ + public function validateSendNewPassword() { + // check permissions + if (!WCF::getSession()->getPermission('admin.user.canEditPassword')) { + return array(); + } + + return $this->__validateAccessibleGroups(array_keys($this->objects)); + } } diff --git a/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php b/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php new file mode 100644 index 0000000000..fb054e1125 --- /dev/null +++ b/wcfsetup/install/files/lib/system/worker/SendNewPasswordWorker.class.php @@ -0,0 +1,109 @@ + + * @package com.woltlab.wcf + * @subpackage system.worker + * @category Community Framework + */ +class SendNewPasswordWorker extends AbstractWorker { + /** + * @see \wcf\system\worker\AbstractWorker::$limit + */ + protected $limit = 50; + + /** + * @see \wcf\system\worker\IWorker::countObjects() + */ + public function countObjects() { + $userList = new UserList(); + $userList->getConditionBuilder()->add('user_table.userID IN (?)', array($this->parameters['userIDs'])); + + return $userList->countObjects(); + } + + /** + * @see \wcf\system\worker\IWorker::execute() + */ + public function execute() { + $userList = new UserList(); + $userList->decoratorClassName = 'wcf\data\user\UserEditor'; + $userList->getConditionBuilder()->add('user_table.userID IN (?)', array($this->parameters['userIDs'])); + $userList->sqlLimit = $this->limit; + $userList->sqlOffset = $this->limit * $this->loopCount; + $userList->readObjects(); + + foreach ($userList as $userEditor) { + $this->sendNewPassword($userEditor); + } + } + + /** + * @see \wcf\system\worker\IWorker::getProceedURL() + */ + public function getProceedURL() { + return LinkHandler::getInstance()->getLink('UserList'); + } + + /** + * @see \wcf\system\worker\IWorker::getProgress() + */ + public function getProgress() { + $progress = parent::getProgress(); + + if ($progress == 100) { + // unmark users + ClipboardHandler::getInstance()->unmark($this->parameters['userIDs'], ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user')); + } + + return $progress; + } + + /** + * Sends a new password to the given user. + * + * @param \wcf\data\user\UserEditor $userEditor + */ + protected function sendNewPassword(UserEditor $userEditor) { + $newPassword = PasswordUtil::getRandomPassword(); + + $userAction = new UserAction(array($userEditor), 'update', array( + 'data' => array( + 'password' => $newPassword + ) + )); + $userAction->executeAction(); + + // send mail + $mail = new Mail(array($userEditor->username => $userEditor->email), $userEditor->getLanguage()->getDynamicVariable('wcf.acp.user.sendNewPassword.mail.subject'), $userEditor->getLanguage()->getDynamicVariable('wcf.acp.user.sendNewPassword.mail', array( + 'password' => $newPassword, + 'username' => $userEditor->username, + ))); + $mail->send(); + } + + /** + * @see \wcf\system\worker\IWorker::validate() + */ + public function validate() { + WCF::getSession()->checkPermissions(array('admin.user.canEditPassword')); + + if (!isset($this->parameters['userIDs']) || !is_array($this->parameters['userIDs']) || empty($this->parameters['userIDs'])) { + throw new SystemException("'userIDs' parameter is missing or invalid"); + } + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index dadecac867..c748be832a 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1372,6 +1372,14 @@ Wenn Sie unter System -> Optionen -> Allgemein -> E-Mails alle {#$usersAwaitingApproval} Benutzer {if $usersAwaitingApproval == 1}wartet auf seine{else}warten auf ihre{/if} Aktivierung.]]> + + + @@ -1489,6 +1497,8 @@ Fehler sind beispielsweise: + + @@ -2094,7 +2104,7 @@ Fehler sind beispielsweise: diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 8dd5711fae..6c137eeb97 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1372,6 +1372,14 @@ You can define the default sender in System -> Options -> General -> {#$usersAwaitingApproval} User{if $usersAwaitingApproval != 1}s{/if} {if $usersAwaitingApproval == 1}is{else}are{/if} awaiting your approval.]]> + + + @@ -1488,6 +1496,8 @@ Errors are: + + @@ -2093,7 +2103,7 @@ Errors are: -- 2.20.1