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\OverrideUserSettings;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2023, Afterlogic Corp.
14: *
15: * @property Settings $oModuleSettings
16: *
17: * @package Modules
18: */
19: class Module extends \Aurora\System\Module\AbstractModule
20: {
21: public function init()
22: {
23: $this->subscribeEvent('Core::CreateUser::after', array($this, 'onAfterCreateUser'));
24: }
25:
26: /**
27: * @return Module
28: */
29: public static function getInstance()
30: {
31: return parent::getInstance();
32: }
33:
34: /**
35: * @return Module
36: */
37: public static function Decorator()
38: {
39: return parent::Decorator();
40: }
41:
42: /**
43: * @return Settings
44: */
45: public function getModuleSettings()
46: {
47: return $this->oModuleSettings;
48: }
49:
50: public function onAfterCreateUser(&$aArgs, &$mResult)
51: {
52: $iUserId = isset($mResult) && (int) $mResult > 0 ? (int) $mResult : 0;
53: if ($iUserId > 0) {
54: $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($iUserId);
55:
56: if ($oUser) {
57: $aDomains = $this->oModuleSettings->Domains;
58: if (is_array($aDomains) && !empty($aDomains)) {
59: $sUserDomain = \MailSo\Base\Utils::GetDomainFromEmail($oUser->PublicId);
60: foreach ($aDomains as $aDomain) {
61: if ($aDomain["name"] === $sUserDomain && isset($aDomain["modules"]) && is_array($aDomain["modules"])) {
62: foreach ($aDomain["modules"] as $sModuleName) {
63: $oUser->disableModule($sModuleName);
64: \Aurora\Modules\Core\Module::Decorator()->UpdateUserObject($oUser);
65: }
66: }
67: }
68: }
69: }
70: }
71: }
72: }
73: