| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\DropboxAuthWebclient; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | class Module extends \Aurora\System\Module\AbstractWebclientModule |
| 22: | { |
| 23: | protected $sService = 'dropbox'; |
| 24: | |
| 25: | protected $aRequireModules = array( |
| 26: | 'OAuthIntegratorWebclient', |
| 27: | 'Dropbox' |
| 28: | ); |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | public static function getInstance() |
| 34: | { |
| 35: | return parent::getInstance(); |
| 36: | } |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public static function Decorator() |
| 42: | { |
| 43: | return parent::Decorator(); |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function getModuleSettings() |
| 50: | { |
| 51: | return $this->oModuleSettings; |
| 52: | } |
| 53: | |
| 54: | |
| 55: | protected function issetScope($sScope) |
| 56: | { |
| 57: | return in_array($sScope, explode(' ', $this->oModuleSettings->Scopes)); |
| 58: | } |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | public function init() |
| 66: | { |
| 67: | $this->subscribeEvent('OAuthIntegratorWebclient::GetServices::after', array($this, 'onAfterGetServices')); |
| 68: | $this->subscribeEvent('OAuthIntegratorAction', array($this, 'onOAuthIntegratorAction')); |
| 69: | $this->subscribeEvent('Dropbox::GetSettings', array($this, 'onGetSettings')); |
| 70: | $this->subscribeEvent('Dropbox::UpdateSettings::after', array($this, 'onAfterUpdateSettings')); |
| 71: | } |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | |
| 80: | public function onAfterGetServices($aArgs, &$aServices) |
| 81: | { |
| 82: | $oModule = \Aurora\Modules\Dropbox\Module::getInstance(); |
| 83: | if ($oModule) { |
| 84: | $sId = $oModule->oModuleSettings->Id; |
| 85: | $sSecret = $oModule->oModuleSettings->Secret; |
| 86: | |
| 87: | if ($oModule->oModuleSettings->EnableModule && $this->issetScope('auth') && !empty($sId) && !empty($sSecret)) { |
| 88: | $aServices[] = $this->sService; |
| 89: | } |
| 90: | } |
| 91: | } |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | |
| 98: | |
| 99: | |
| 100: | public function onOAuthIntegratorAction($aArgs, &$mResult) |
| 101: | { |
| 102: | if ($aArgs['Service'] === $this->sService) { |
| 103: | $sScopes = isset($_COOKIE['oauth-scopes']) ? $_COOKIE['oauth-scopes'] : ''; |
| 104: | $mResult = false; |
| 105: | $oConnector = new Classes\Connector($this); |
| 106: | $oDropboxModule = \Aurora\Modules\Dropbox\Module::getInstance(); |
| 107: | if ($oConnector) { |
| 108: | $mResult = $oConnector->Init( |
| 109: | $oDropboxModule->oModuleSettings->Id, |
| 110: | $oDropboxModule->oModuleSettings->Secret, |
| 111: | $sScopes |
| 112: | ); |
| 113: | } |
| 114: | return true; |
| 115: | } |
| 116: | } |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | |
| 125: | public function onGetSettings($aArgs, &$mResult) |
| 126: | { |
| 127: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 128: | |
| 129: | if ($oUser) { |
| 130: | $aScope = array( |
| 131: | 'Name' => 'auth', |
| 132: | 'Description' => $this->i18N('SCOPE_AUTH'), |
| 133: | 'Value' => false |
| 134: | ); |
| 135: | if ($oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) { |
| 136: | $aScope['Value'] = $this->issetScope('auth'); |
| 137: | $mResult['Scopes'][] = $aScope; |
| 138: | } |
| 139: | if ($oUser->isNormalOrTenant()) { |
| 140: | if ($aArgs['OAuthAccount'] instanceof \Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount) { |
| 141: | $aScope['Value'] = $aArgs['OAuthAccount']->issetScope('auth'); |
| 142: | } |
| 143: | if ($this->issetScope('auth')) { |
| 144: | $mResult['Scopes'][] = $aScope; |
| 145: | } |
| 146: | } |
| 147: | } |
| 148: | } |
| 149: | |
| 150: | public function onAfterUpdateSettings($aArgs, &$mResult) |
| 151: | { |
| 152: | $sScope = ''; |
| 153: | if (isset($aArgs['Scopes']) && is_array($aArgs['Scopes'])) { |
| 154: | foreach ($aArgs['Scopes'] as $aScope) { |
| 155: | if ($aScope['Name'] === 'auth') { |
| 156: | if ($aScope['Value']) { |
| 157: | $sScope = 'auth'; |
| 158: | break; |
| 159: | } |
| 160: | } |
| 161: | } |
| 162: | } |
| 163: | $this->setConfig('Scopes', $sScope); |
| 164: | $this->saveModuleConfig(); |
| 165: | } |
| 166: | } |
| 167: | |