Esempio n. 1
0
 protected function action_oauth()
 {
     if (empty($this->bean->id)) {
         return $this->set_redirect('index.php');
     }
     if (!$this->bean->ACLAccess('save')) {
         ACLController::displayNoAccess(true);
         sugar_cleanup(true);
         return true;
     }
     if (empty($_REQUEST['oauth_error'])) {
         $this->api = ExternalAPIFactory::loadAPI($this->bean->application, true);
         $reply = $this->api->checkLogin($this->bean);
         if (!$reply['success']) {
             return $this->failed(translate('LBL_AUTH_ERROR', $this->bean->module_dir));
         } else {
             $this->bean->validated();
         }
     }
     // This is a tweak so that we can automatically close windows if requested by the external account system
     if (isset($_REQUEST['closeWhenDone']) && $_REQUEST['closeWhenDone'] == 1) {
         if (!empty($_REQUEST['callbackFunction']) && !empty($_REQUEST['application'])) {
             $js = '<script type="text/javascript">window.opener.' . $_REQUEST['callbackFunction'] . '("' . $_REQUEST['application'] . '"); window.close();</script>';
         } else {
             if (!empty($_REQUEST['refreshParentWindow'])) {
                 $js = '<script type="text/javascript">window.opener.location.reload();window.close();</script>';
             } else {
                 $js = '<script type="text/javascript">window.close();</script>';
             }
         }
         echo $js;
         return;
     }
     // redirect to detail view, as in save
     return parent::post_save();
 }