1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
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: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
16: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
17: * @copyright Copyright (c) 2023, Afterlogic Corp.
18: *
19: * @property Settings $oModuleSettings
20: *
21: * @package Modules
22: */
23: class Module extends \Aurora\System\Module\AbstractWebclientModule
24: {
25: /***** public functions might be called with web API *****/
26:
27: /**
28: * @return Module
29: */
30: public static function getInstance()
31: {
32: return parent::getInstance();
33: }
34:
35: /**
36: * @return Module
37: */
38: public static function Decorator()
39: {
40: return parent::Decorator();
41: }
42:
43: /**
44: * @return Settings
45: */
46: public function getModuleSettings()
47: {
48: return $this->oModuleSettings;
49: }
50:
51: /**
52: * Obtains list of module settings for authenticated user.
53: *
54: * @return array
55: */
56: public function GetSettings()
57: {
58: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
59:
60: return array(
61: 'ServerModuleName' => $this->oModuleSettings->ServerModuleName,
62: 'HashModuleName' => $this->oModuleSettings->HashModuleName,
63: 'CustomLoginUrl' => $this->oModuleSettings->CustomLoginUrl,
64: 'DemoLogin' => $this->oModuleSettings->DemoLogin,
65: 'DemoPassword' => $this->oModuleSettings->DemoPassword,
66: 'InfoText' => $this->oModuleSettings->InfoText,
67: 'BottomInfoHtmlText' => $this->oModuleSettings->BottomInfoHtmlText,
68: 'LoginSignMeType' => $this->oModuleSettings->LoginSignMeType,
69: 'AllowChangeLanguage' => $this->oModuleSettings->AllowChangeLanguage,
70: 'UseDropdownLanguagesView' => $this->oModuleSettings->UseDropdownLanguagesView,
71: );
72: }
73:
74: public function Login($Login, $Password, $Domain, $Language = '', $SignMe = false)
75: {
76: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
77:
78: $sLogin = \trim($Login);
79: $sDomain = \trim($Domain);
80:
81: if (empty($sLogin) || empty($sDomain)) {
82: throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter);
83: }
84:
85: return \Aurora\Modules\StandardLoginFormWebclient\Module::Decorator()->Login($sLogin . '@' . $sDomain, $Password, $Language, $SignMe);
86: }
87:
88: public function GetMailDomains()
89: {
90: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
91:
92: $bPrevState = \Aurora\System\Api::skipCheckUserRole(true);
93: $aAllDomains = [];
94: $oTenant = \Aurora\System\Api::getTenantByWebDomain();
95: $aArgs = [];
96: if ($oTenant instanceof \Aurora\Modules\Core\Models\Tenant) {
97: $aArgs = [
98: 'TenantId' => $oTenant->Id
99: ];
100: }
101: $mResult = [];
102: $this->broadcastEvent(
103: 'GetMailDomains',
104: $aArgs,
105: $mResult
106: );
107: if (is_array($mResult) && !empty($mResult)) {
108: $aAllDomains = $mResult;
109: } else {
110: $Filter = null;
111: if ($oTenant instanceof \Aurora\Modules\Core\Models\Tenant) {
112: $Filter = Server::orWhere(function ($query) use ($oTenant) {
113: $query->where('OwnerType', ServerOwnerType::SuperAdmin)
114: ->where(function ($query) use ($oTenant) {
115: $query->where('TenantId', $oTenant->Id)
116: ->where('OwnerType', ServerOwnerType::Tenant);
117: });
118: });
119: } else {
120: //get all servers for all tenants
121: $Filter = Server::where('OwnerType', ServerOwnerType::Tenant)
122: ->orWhere('OwnerType', ServerOwnerType::SuperAdmin);
123: }
124:
125: $aServers = MailModule::getInstance()->getServersManager()->getServerListByFilter($Filter);
126: if ($aServers) {
127: /** @var Server $oServer */
128: foreach ($aServers as $oServer) {
129: $aDomains = explode("\n", $oServer->Domains);
130: $aDomains = array_filter($aDomains, function ($sDomain) {
131: return $sDomain !== '*';
132: });
133: if (count($aDomains) > 0) {
134: $aAllDomains = array_merge($aAllDomains, $aDomains);
135: }
136: }
137: }
138: }
139: \Aurora\System\Api::skipCheckUserRole($bPrevState);
140:
141: return array_unique($aAllDomains);
142: }
143: /***** public functions might be called with web API *****/
144: }
145: