public function sendRequest($method = null, $args = null, $postmethod = 'get', $tryagain = true) { try { $result = parent::sendRequest($method, $args, $postmethod); if ($tryagain && is_null($result)) { $result = parent::sendRequest($method, $args, $postmethod, false); } elseif (is_null($result)) { throw new CMSException("No response", $method, 8888, 'n/a'); } if (is_array($result) && isset($result['error']) && $result['error']) { throw new CMSException($result['error']['message'], $method, $result['error']['code'], $result['error']['field']); } } catch (CMSException $e) { } if (isset($result['response'])) { return $result['response']; } return $result; }
// Use the right API d('API_KEY', $_SESSION['api_mode'] == 'dev' ? 'bcppxparnj' : 'vnjjhwwtrp'); // i.wayne.edu // Include the API include_once ROOT . '/lib/phpcms/phpcms.php'; include_once ROOT . '/lib/functions.php'; // Initialize the API $c = new Phpcms(API_KEY, MODE); $c->debug = false; //$c->parser = 'raw'; //$c->sendRequest('api/information/version', 'get'); //Pre($c); // If trying to login if (isset($_POST['accessid']) && isset($_POST['password'])) { $login_credentials = array('accessid' => strtolower($_POST['accessid']), 'password' => $_POST['password']); $login_response = $c->sendRequest('api/user/auth', $login_credentials, 'post', true); Pre($login_response); // Store the session ID in the session if (isset($login_response['response']['auth']['sessionid'])) { $_SESSION['sessionid'] = $login_response['response']['auth']['sessionid']; // Get the users information $user_details = $c->sendRequest('api/user/info', array('accessid' => $_POST['accessid'])); // Save the basic information about this user $_SESSION['user_details'] = $user_details['response']['user']; // Set the user message Flash('Welcome back ' . $_SESSION['user_details']['first_name'] . '!', 'success'); } else { // Set the user error message Flash('Incorrect AccessID/password. Please try again', 'error'); } //Pre($login_response);