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