/** * Delete a user account. * * @since 2.0.0 * @access public * @param int $UserID Unique ID. * @param string $Method Type of deletion to do (delete, keep, or wipe). */ public function delete($UserID = '', $Method = '') { $this->permission('Garden.Users.Delete'); $Session = Gdn::session(); if ($Session->User->UserID == $UserID) { trigger_error(errorMessage("You cannot delete the user you are logged in as.", $this->ClassName, 'FetchViewLocation'), E_USER_ERROR); } $this->addSideMenu('dashboard/user'); $this->title(t('Delete User')); $RoleModel = new RoleModel(); $AllRoles = $RoleModel->getArray(); // By default, people with access here can freely assign all roles $this->RoleData = $AllRoles; $UserModel = new UserModel(); $this->User = $UserModel->getID($UserID); try { $CanDelete = true; $this->EventArguments['CanDelete'] =& $CanDelete; $this->EventArguments['TargetUser'] =& $this->User; // These are all the 'effective' roles for this delete action. This list can // be trimmed down from the real list to allow subsets of roles to be // edited. $this->EventArguments['RoleData'] =& $this->RoleData; $UserRoleData = $UserModel->getRoles($UserID)->resultArray(); $RoleIDs = array_column($UserRoleData, 'RoleID'); $RoleNames = array_column($UserRoleData, 'Name'); $this->UserRoleData = ArrayCombine($RoleIDs, $RoleNames); $this->EventArguments['UserRoleData'] =& $this->UserRoleData; $this->fireEvent("BeforeUserDelete"); $this->setData('CanDelete', $CanDelete); $Method = in_array($Method, array('delete', 'keep', 'wipe')) ? $Method : ''; $this->Method = $Method; if ($Method != '') { $this->View = 'deleteconfirm'; } if ($this->Form->authenticatedPostBack() && $Method != '') { $UserModel->delete($UserID, array('DeleteMethod' => $Method)); $this->View = 'deletecomplete'; } } catch (Exception $Ex) { $this->Form->addError($Ex); } $this->render(); }