| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\MailLoginFormWebclient; |
| 9: | |
| 10: | use Aurora\Modules\Mail\Enums\ServerOwnerType; |
| 11: | use Aurora\Modules\Mail\Models\Server; |
| 12: | use Aurora\Modules\Mail\Module as MailModule; |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | class Module extends \Aurora\System\Module\AbstractWebclientModule |
| 22: | { |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function GetSettings() |
| 30: | { |
| 31: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
| 32: | |
| 33: | return array( |
| 34: | 'ServerModuleName' => $this->getConfig('ServerModuleName', ''), |
| 35: | 'HashModuleName' => $this->getConfig('HashModuleName', ''), |
| 36: | 'CustomLoginUrl' => $this->getConfig('CustomLoginUrl', ''), |
| 37: | 'DemoLogin' => $this->getConfig('DemoLogin', ''), |
| 38: | 'DemoPassword' => $this->getConfig('DemoPassword', ''), |
| 39: | 'InfoText' => $this->getConfig('InfoText', ''), |
| 40: | 'BottomInfoHtmlText' => $this->getConfig('BottomInfoHtmlText', ''), |
| 41: | 'LoginSignMeType' => $this->getConfig('LoginSignMeType', 0), |
| 42: | 'AllowChangeLanguage' => $this->getConfig('AllowChangeLanguage', true), |
| 43: | 'UseDropdownLanguagesView' => $this->getConfig('UseDropdownLanguagesView', false), |
| 44: | ); |
| 45: | } |
| 46: | |
| 47: | public function Login($Login, $Password, $Domain, $Language = '', $SignMe = false) |
| 48: | { |
| 49: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
| 50: | |
| 51: | $sLogin = \trim($Login); |
| 52: | $sDomain = \trim($Domain); |
| 53: | |
| 54: | if (empty($sLogin) || empty($sDomain)) { |
| 55: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 56: | } |
| 57: | |
| 58: | return \Aurora\Modules\StandardLoginFormWebclient\Module::Decorator()->Login($sLogin . '@' . $sDomain, $Password, $Language, $SignMe); |
| 59: | } |
| 60: | |
| 61: | public function GetMailDomains() |
| 62: | { |
| 63: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
| 64: | |
| 65: | $bPrevState = \Aurora\System\Api::skipCheckUserRole(true); |
| 66: | $aAllDomains = []; |
| 67: | $oTenant = \Aurora\System\Api::getTenantByWebDomain(); |
| 68: | $aArgs = []; |
| 69: | if ($oTenant instanceof \Aurora\Modules\Core\Models\Tenant) { |
| 70: | $aArgs = [ |
| 71: | 'TenantId' => $oTenant->Id |
| 72: | ]; |
| 73: | } |
| 74: | $mResult = []; |
| 75: | $this->broadcastEvent( |
| 76: | 'GetMailDomains', |
| 77: | $aArgs, |
| 78: | $mResult |
| 79: | ); |
| 80: | if (is_array($mResult) && !empty($mResult)) { |
| 81: | $aAllDomains = $mResult; |
| 82: | } else { |
| 83: | $Filter = null; |
| 84: | if ($oTenant instanceof \Aurora\Modules\Core\Models\Tenant) { |
| 85: | $Filter = Server::orWhere(function ($query) use ($oTenant) { |
| 86: | $query->where('OwnerType', ServerOwnerType::SuperAdmin) |
| 87: | ->where(function ($query) use ($oTenant) { |
| 88: | $query->where('TenantId', $oTenant->Id) |
| 89: | ->where('OwnerType', ServerOwnerType::Tenant); |
| 90: | }); |
| 91: | }); |
| 92: | } else { |
| 93: | |
| 94: | $Filter = Server::where('OwnerType', ServerOwnerType::Tenant) |
| 95: | ->orWhere('OwnerType', ServerOwnerType::SuperAdmin); |
| 96: | } |
| 97: | |
| 98: | $aServers = MailModule::getInstance()->getServersManager()->getServerListByFilter($Filter); |
| 99: | if ($aServers) { |
| 100: | foreach ($aServers as $oServer) { |
| 101: | $aDomains = explode("\n", $oServer->Domains); |
| 102: | $aDomains = array_filter($aDomains, function ($sDomain) { |
| 103: | return $sDomain !== '*'; |
| 104: | }); |
| 105: | if (count($aDomains) > 0) { |
| 106: | $aAllDomains = array_merge($aAllDomains, $aDomains); |
| 107: | } |
| 108: | } |
| 109: | } |
| 110: | } |
| 111: | \Aurora\System\Api::skipCheckUserRole($bPrevState); |
| 112: | |
| 113: | return array_unique($aAllDomains); |
| 114: | } |
| 115: | |
| 116: | } |
| 117: | |