/** * Get Request Handler * * This method is called when a request is a GET * * @return array */ public function executeGet() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { return $valid; } $username = $this->getParam('username'); $password = $this->getParam('password'); $contact_id = $this->getParam('contact_id', self::TYPE_INT); // Attempt to login as user, a little bit of a hack as we currently // require the $_POST['login'] var to be set as well as a global AppUI $AppUI = new CAppUI(); $GLOBALS['AppUI'] = $AppUI; $_POST['login'] = '******'; if (!$AppUI->login($username, $password)) { throw new Frapi_Error('INVALID_LOGIN'); } $contact = new CContact(); $allowed_contacts = $contact->getAllowedRecords($AppUI->user_id); // Contact ID is the key, so lets get them in an array so we can // easily check $allowed_contacts = array_keys($allowed_contacts); if (!in_array($contact_id, $allowed_contacts)) { throw new Frapi_Error('PERMISSION_ERROR'); } // User has permission so load the contact for display $contact_array = (array) $contact->load($contact_id); $contact_array['contact_methods'] = $contact->getContactMethods(); // Remove the data that is not for display unset($contact_array['_tbl_prefix'], $contact_array['_tbl'], $contact_array['_tbl_key'], $contact_array['_error'], $contact_array['_query'], $contact_array['_tbl_module']); $this->data['contact'] = $contact_array; $this->data['success'] = true; return $this->toArray(); }
/** * Get Request Handler * * This method is called when a request is a GET * * @return array */ public function executeGet() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { return $valid; } $username = $this->getParam('username'); $password = $this->getParam('password'); // Attempt to login as user, a little bit of a hack as we currently // require the $_POST['login'] var to be set as well as a global AppUI $AppUI = new CAppUI(); $GLOBALS['AppUI'] = $AppUI; $_POST['login'] = '******'; if (!$AppUI->login($username, $password)) { throw new Frapi_Error('INVALID_LOGIN'); } $contact = new CContact(); $this->data['contacts'] = $contact->getAllowedRecords($AppUI->user_id); $this->data['success'] = true; return $this->toArray(); }