芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/www/cloud.pulsehost.co.uk/modules/MailChangePasswordPoppassdPlugin/Module.php
oPopPassD = null; $this->subscribeEvent('Mail::Account::ToResponseArray', array($this, 'onMailAccountToResponseArray')); $this->subscribeEvent('Mail::ChangeAccountPassword', array($this, 'onChangeAccountPassword')); $this->subscribeEvent('StandardResetPassword::ChangeAccountPassword', array($this, 'onChangeAccountPassword')); } /** * @return Module */ public static function getInstance() { return parent::getInstance(); } /** * @return Module */ public static function Decorator() { return parent::Decorator(); } /** * @return Settings */ public function getModuleSettings() { return $this->oModuleSettings; } /** * Adds to account response array information about if allowed to change the password for this account. * @param array $aArguments * @param mixed $mResult */ public function onMailAccountToResponseArray($aArguments, &$mResult) { $oAccount = $aArguments['Account']; if ($oAccount && $this->checkCanChangePassword($oAccount)) { if (!isset($mResult['Extend']) || !is_array($mResult['Extend'])) { $mResult['Extend'] = []; } $mResult['Extend']['AllowChangePasswordOnMailServer'] = true; } } /** * Tries to change password for account if allowed. * @param array $aArguments * @param mixed $mResult */ public function onChangeAccountPassword($aArguments, &$mResult) { $bPasswordChanged = false; $bBreakSubscriptions = false; $oAccount = $aArguments['Account']; if ($oAccount && $this->checkCanChangePassword($oAccount) && ($oAccount->getPassword() === $aArguments['CurrentPassword'] || isset($aArguments['SkipCurrentPasswordCheck']) && $aArguments['SkipCurrentPasswordCheck'])) { $bPasswordChanged = $this->changePassword($oAccount, $aArguments['NewPassword']); $bBreakSubscriptions = true; // break if Poppassd plugin tries to change password in this account. } if (is_array($mResult)) { $mResult['AccountPasswordChanged'] = $mResult['AccountPasswordChanged'] || $bPasswordChanged; } return $bBreakSubscriptions; } /** * Checks if allowed to change password for account. * @param \Aurora\Modules\Mail\Models\MailAccount $oAccount * @return bool */ protected function checkCanChangePassword($oAccount) { $bFound = in_array('*', $this->oModuleSettings->SupportedServers); if (!$bFound) { $oServer = $oAccount->getServer(); if ($oServer && in_array($oServer->IncomingServer, $this->oModuleSettings->SupportedServers)) { $bFound = true; } } return $bFound; } /** * Tries to change password for account. * @param \Aurora\Modules\Mail\Models\MailAccount $oAccount * @param string $sPassword * @return boolean * @throws \Aurora\System\Exceptions\ApiException */ protected function changePassword($oAccount, $sPassword) { $bResult = false; if (0 < strlen($oAccount->getPassword()) && $oAccount->getPassword() !== $sPassword) { if (null === $this->oPopPassD) { $this->oPopPassD = new Poppassd( $this->oModuleSettings->Host, $this->oModuleSettings->Port ); } if ($this->oPopPassD && $this->oPopPassD->Connect()) { try { if ($this->oPopPassD->Login($oAccount->IncomingLogin, $oAccount->getPassword())) { $aNewPasswordResult = $this->oPopPassD->NewPass($sPassword); if (!$aNewPasswordResult[0]) { throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Exceptions\Errs::UserManager_AccountNewPasswordRejected, null, $aNewPasswordResult[1]); } else { $bResult = true; } } else { throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Exceptions\Errs::UserManager_AccountOldPasswordNotCorrect); } } catch (\Exception $oException) { $this->oPopPassD->Disconnect(); throw $oException; } } else { throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Exceptions\Errs::UserManager_AccountNewPasswordUpdateError); } } return $bResult; } /** * Obtains list of module settings for super admin. * @return array */ public function GetSettings() { \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); $sSupportedServers = implode("\n", $this->oModuleSettings->SupportedServers); $aAppData = array( 'SupportedServers' => $sSupportedServers, 'Host' => $this->oModuleSettings->Host, 'Port' => $this->oModuleSettings->Port, ); return $aAppData; } /** * Updates module's super admin settings. * @param string $SupportedServers * @param string $Host * @param int $Port * @return boolean */ public function UpdateSettings($SupportedServers, $Host, $Port) { \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); $aSupportedServers = preg_split('/\r\n|[\r\n]/', $SupportedServers); $this->setConfig('SupportedServers', $aSupportedServers); $this->setConfig('Host', $Host); $this->setConfig('Port', $Port); return $this->saveModuleConfig(); } }