1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\FacebookAuthWebclient; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | class Module extends \Aurora\System\Module\AbstractWebclientModule |
22: | { |
23: | protected $sService = 'facebook'; |
24: | |
25: | protected $aRequireModules = array( |
26: | 'OAuthIntegratorWebclient', |
27: | 'Facebook' |
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('Facebook::GetSettings', array($this, 'onGetSettings')); |
70: | $this->subscribeEvent('Facebook::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\Facebook\Module::getInstance(); |
83: | $sId = $oModule->oModuleSettings->Id; |
84: | $sSecret = $oModule->oModuleSettings->Secret; |
85: | |
86: | if ($oModule->oModuleSettings->EnableModule && $this->issetScope('auth') && !empty($sId) && !empty($sSecret)) { |
87: | $aServices[] = $this->sService; |
88: | } |
89: | } |
90: | |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | public function onOAuthIntegratorAction($aArgs, &$mResult) |
99: | { |
100: | if ($aArgs['Service'] === $this->sService) { |
101: | $sScopes = isset($_COOKIE['oauth-scopes']) ? $_COOKIE['oauth-scopes'] : ''; |
102: | $mResult = false; |
103: | $oConnector = new Classes\Connector($this); |
104: | $oFacebookModule = \Aurora\Modules\Facebook\Module::getInstance(); |
105: | if ($oConnector) { |
106: | $mResult = $oConnector->Init( |
107: | $oFacebookModule->oModuleSettings->Id, |
108: | $oFacebookModule->oModuleSettings->Secret, |
109: | $sScopes |
110: | ); |
111: | } |
112: | return true; |
113: | } |
114: | } |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | |
123: | public function onGetSettings($aArgs, &$mResult) |
124: | { |
125: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
126: | |
127: | if ($oUser) { |
128: | $aScope = array( |
129: | 'Name' => 'auth', |
130: | 'Description' => $this->i18N('SCOPE_AUTH'), |
131: | 'Value' => false |
132: | ); |
133: | if ($oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) { |
134: | $aScope['Value'] = $this->issetScope('auth'); |
135: | $mResult['Scopes'][] = $aScope; |
136: | } |
137: | if ($oUser->isNormalOrTenant()) { |
138: | if ($aArgs['OAuthAccount'] instanceof \Aurora\Modules\OAuthIntegratorWebclient\Models\OauthAccount) { |
139: | $aScope['Value'] = $aArgs['OAuthAccount']->issetScope('auth'); |
140: | } |
141: | if ($this->issetScope('auth')) { |
142: | $mResult['Scopes'][] = $aScope; |
143: | } |
144: | } |
145: | } |
146: | } |
147: | |
148: | public function onAfterUpdateSettings($aArgs, &$mResult) |
149: | { |
150: | $sScope = ''; |
151: | if (isset($aArgs['Scopes']) && is_array($aArgs['Scopes'])) { |
152: | foreach ($aArgs['Scopes'] as $aScope) { |
153: | if ($aScope['Name'] === 'auth') { |
154: | if ($aScope['Value']) { |
155: | $sScope = 'auth'; |
156: | break; |
157: | } |
158: | } |
159: | } |
160: | } |
161: | $this->setConfig('Scopes', $sScope); |
162: | $this->saveModuleConfig(); |
163: | } |
164: | } |
165: | |