Преглед изворни кода

Ticket #3482 - When site's key&secret is changed reset oAuth sessions in apps market since it cause some errors.

AntonLV пре 4 година
родитељ
комит
a0c28428ae

+ 7 - 0
install/sql/system.sql

@@ -1832,6 +1832,13 @@ SET @iIdHandler = LAST_INSERT_ID();
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('sys_images_custom', 'file_deleted', @iIdHandler);
 
+INSERT INTO `sys_alerts_handlers` (`name`, `service_call`) VALUES
+('sys_settings_change_kands', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:27:"alert_response_change_kands";s:6:"params";a:0:{}s:5:"class";s:27:"TemplStudioSettingsServices";}');
+SET @iIdHandler = LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+('system', 'save_setting', @iIdHandler);
+
 INSERT INTO `sys_alerts_handlers` (`name`, `service_call`) VALUES 
 ('sys_settings_storage_change', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:37:"alert_response_process_storage_change";s:5:"class";s:13:"TemplServices";}');
 SET @iHandler = LAST_INSERT_ID();

+ 10 - 4
studio/classes/BxDolStudioOAuth.php

@@ -36,6 +36,15 @@ class BxDolStudioOAuth extends BxDolFactory
         $this->sErrorMessage = 'oauth_err_message';
     }
 
+    static function unsetAuthorized()
+    {
+        $oSession = BxDolSession::getInstance();
+        $oSession->unsetValue(self::$sSessionKeyToken);
+        $oSession->unsetValue(self::$sSessionKeyAuthorized);
+        $oSession->unsetValue(self::$sSessionKeyAuthorizedUser);
+        $oSession->unsetValue(self::$sSessionKeyAuthorizedOwner);
+    }
+
     static function isAuthorizedClient()
     {
         return (int)BxDolSession::getInstance()->getValue(self::$sSessionKeyAuthorized) == 1;
@@ -109,10 +118,7 @@ class BxDolStudioOAuth extends BxDolFactory
 
     protected function unsetAuthorizedUser()
     {
-        $this->oSession->unsetValue(self::$sSessionKeyToken);
-        $this->oSession->unsetValue(self::$sSessionKeyAuthorized);
-        $this->oSession->unsetValue(self::$sSessionKeyAuthorizedUser);
-        $this->oSession->unsetValue(self::$sSessionKeyAuthorizedOwner);
+        self::unsetAuthorized();
     }
 
     protected function isServerError($aResult)

+ 15 - 4
studio/template/scripts/BxBaseStudioSettingsServices.php

@@ -13,7 +13,7 @@
  */
 class BxBaseStudioSettingsServices extends BxDol
 {
-	protected $oDb;
+    protected $oDb;
 
     public function __construct()
     {
@@ -22,10 +22,21 @@ class BxBaseStudioSettingsServices extends BxDol
         $this->oDb = new BxDolStudioSettingsQuery();
     }
 
-	public function serviceAlertResponseSysImagesCustomFileDeleted($oAlert)
+    public function serviceAlertResponseChangeKands($oAlert)
+    {
+        if(!in_array($oAlert->aExtras['option'], ['sys_oauth_key', 'sys_oauth_secret']))
+            return;
+
+        if(strcmp($oAlert->aExtras['value'], $oAlert->aExtras['value_prior']) == 0)
+            return;
+
+        BxDolStudioOAuth::unsetAuthorized();
+    }
+
+    public function serviceAlertResponseSysImagesCustomFileDeleted($oAlert)
     {
     	if(!isset($oAlert->aExtras['ghost']['content_id']))
-    		return;
+            return;
 
     	$iOption = (int)$oAlert->aExtras['ghost']['content_id'];
 
@@ -33,7 +44,7 @@ class BxBaseStudioSettingsServices extends BxDol
     	$this->oDb->getOptions(array('type' => 'by_id', 'value' => $iOption), $aOption, false);
 
     	if(!empty($aOption) && is_array($aOption))
-    		setParam($aOption['name'], 0);
+            setParam($aOption['name'], 0);
     }
 }