| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\MailMasterPassword; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | class Module extends \Aurora\System\Module\AbstractModule |
| 22: | { |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | public function init() |
| 28: | { |
| 29: | $this->subscribeEvent('Core::Login::before', array($this, 'onBeforLogin'), 10); |
| 30: | } |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | public static function getInstance() |
| 36: | { |
| 37: | return parent::getInstance(); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public static function Decorator() |
| 44: | { |
| 45: | return parent::Decorator(); |
| 46: | } |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | public function getModuleSettings() |
| 52: | { |
| 53: | return $this->oModuleSettings; |
| 54: | } |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | public function onBeforLogin(&$aArgs, &$mResult) |
| 63: | { |
| 64: | $sPassword = $this->oModuleSettings->Password; |
| 65: | |
| 66: | if ($sPassword !== false && !empty($sPassword) && password_verify($aArgs['Password'], $sPassword)) { |
| 67: | $oAccount = \Aurora\Modules\Mail\Module::getInstance()->getAccountsManager()->getAccountUsedToAuthorize($aArgs['Login']); |
| 68: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) { |
| 69: | $aArgs['Password'] = $oAccount->getPassword(); |
| 70: | } |
| 71: | } |
| 72: | } |
| 73: | |
| 74: | |
| 75: | public function UpdateSettings($MasterPassword) |
| 76: | { |
| 77: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 78: | |
| 79: | $bResult = false; |
| 80: | |
| 81: | try { |
| 82: | $this->setConfig('Password', password_hash(trim($MasterPassword), PASSWORD_BCRYPT)); |
| 83: | $bResult = $this->saveModuleConfig(); |
| 84: | } catch (\Exception $ex) { |
| 85: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::CanNotSaveSettings); |
| 86: | } |
| 87: | |
| 88: | return $bResult; |
| 89: | } |
| 90: | } |
| 91: | |