| | |
| | | |
| | | $theUserID = current_user_can('manage_options') ? null : get_current_user_id(); |
| | | if ($theUserID === false) { |
| | | error_log('User not logged in'); |
| | | return $this->validationError(['message' => 'Not logged in']); |
| | | } |
| | | $integration = $this->getService($service); |
| | | if (!method_exists($integration, 'switchUser')) { |
| | | return $this->validationError(['message' => 'Cannot get user integration']); |
| | | } |
| | | $integration = $this->getServiceUser($service, $theUserID); |
| | | |
| | | if (!$integration || !method_exists($integration, 'processAction')) { |
| | | error_log('No processAction method'); |
| | | return $this->validationError(['message'=>'Invalid service']); |
| | | } |
| | | |
| | | $integration->switchUser($theUserID); |
| | | |
| | | $integration->getCredentials(); |
| | | |
| | | // Handle the action |
| | |
| | | return $this->success($result); |
| | | |
| | | } catch (Exception $e) { |
| | | error_log(print_r($e->getMessage(), true)); |
| | | return $this->error($e->getMessage()); |
| | | } |
| | | } |