action), $this->admin_actions)) { $this->hasAccess = false; } parent::process(); } protected function failed($error) { SugarApplication::appendErrorMessage($error); $GLOBALS['log']->error("Login error: $error"); $url = 'index.php?module=EAPM&action=EditView&record='.$this->bean->id; return $this->set_redirect($url); } public function pre_save() { parent::pre_save(); $this->api = ExternalAPIFactory::loadAPI($this->bean->application,true); if(empty($this->api)) { return $this->failed(translate('LBL_AUTH_UNSUPPORTED', $this->bean->module_dir)); } if(empty($this->bean->id)){ $eapmBean = EAPM::getLoginInfo($this->bean->application,true); if($eapmBean){ SugarApplication::appendErrorMessage(translate('LBL_APPLICATION_FOUND_NOTICE', $this->bean->module_dir)); $this->bean->id = $eapmBean->id; } } $this->bean->validated = false; $this->bean->save_cleanup(); $this->api->loadEAPM($this->bean); } protected function post_save() { if($this->bean->active) { // do not load bean here since password is already encoded $reply = $this->api->checkLogin(); if ( !$reply['success'] ) { return $this->failed(translate('LBL_AUTH_ERROR', $this->bean->module_dir)); } else { $this->bean->validated(); } } if($this->return_module == 'Users'){ $this->return_action = 'EditView'; } return parent::post_save(); } 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; } $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 = ''; }else if(!empty($_REQUEST['refreshParentWindow'])){ $js = ''; }else{ $js = ''; } echo($js); return; } // redirect to detail view, as in save return parent::post_save(); } } protected function pre_QuickSave(){ if(!empty($_REQUEST['application'])){ $eapmBean = EAPM::getLoginInfo($_REQUEST['application'],true); if (!$eapmBean) { $this->bean->application = $_REQUEST['application']; $this->bean->assigned_user_id = $GLOBALS['current_user']->id; }else{ $this->bean = $eapmBean; $this->bean->active = 1; } $this->pre_save(); }else{ sugar_die("Please pass an application name."); } } public function action_QuickSave(){ $this->action_save(); } protected function post_QuickSave(){ $this->post_save(); } protected function pre_Reauthenticate(){ $this->bean->active = 1; $this->pre_save(); } protected function action_Reauthenticate(){ $this->action_save(); } protected function post_Reauthenticate(){ $this->post_save(); } protected function action_FlushFileCache() { $api = ExternalAPIFactory::loadAPI($_REQUEST['api']); if ( $api == false ) { echo 'FAILED'; return; } if ( method_exists($api,'loadDocCache') ) { $api->loadDocCache(true); } echo 'SUCCESS'; } }