public function Controller_VerifyApi($Sender) { $oasl = new SocialLogin(); // Read arguments, plus some parsing. $api_subdomain = trim(strtolower(Gdn::request()->Post('api_subdomain', ''))); $api_key = trim(Gdn::request()->Post('api_key', '')); $api_secret = trim(Gdn::request()->Post('api_secret', '')); $api_connection_handler = Gdn::request()->Post('api_connection_handler', ''); $api_connection_use_https = Gdn::request()->Post('api_connection_use_https', '0') == '1' ? TRUE : FALSE; // Init status message. $status_message = null; // Check if all fields have been filled out. if (strlen($api_subdomain) == 0 || strlen($api_key) == 0 || strlen($api_secret) == 0) { $status_message = 'error_|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_FILL_OUT'); } else { // Check the handler $api_connection_handler = $api_connection_handler != 'fsockopen' ? 'curl' : 'fsockopen'; // FSOCKOPEN if ($api_connection_handler == 'fsockopen') { if (!$oasl->check_fsockopen($api_connection_use_https)) { $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_USE_AUTO'); } } else { if (!$oasl->check_curl($api_connection_use_https)) { $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_USE_AUTO'); } } // No errors until now. if (empty($status_message)) { // The full domain has been entered. if (preg_match("/([a-z0-9\\-]+)\\.api\\.oneall\\.com/i", $api_subdomain, $matches)) { $api_subdomain = $matches[1]; } // Check format of the subdomain. if (!preg_match("/^[a-z0-9\\-]+\$/i", $api_subdomain)) { $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_SUBDOMAIN_WRONG'); } else { // Construct full API Domain. $api_domain = $api_subdomain . '.api.oneall.com'; $api_resource_url = ($api_connection_use_https ? 'https' : 'http') . '://' . $api_domain . '/tools/ping.json'; // API Credentialls. $api_credentials = array(); $api_credentials['api_key'] = $api_key; $api_credentials['api_secret'] = $api_secret; // Try to establish a connection. $result = $oasl->do_api_request($api_connection_handler, $api_resource_url, $api_credentials); // Parse result. if (is_object($result) && property_exists($result, 'http_code') && property_exists($result, 'http_data')) { switch ($result->http_code) { // Connection successfull. case 200: $status_message = 'success|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_OK'); break; // Authentication Error. // Authentication Error. case 401: $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_KEYS_WRONG'); break; // Wrong Subdomain. // Wrong Subdomain. case 404: $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_SUBDOMAIN_WRONG'); break; // Other error. // Other error. default: $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_CHECK_COM'); break; } } else { $status_message = 'error|' . T('OA_SOCIAL_LOGIN_API_CREDENTIALS_CHECK_COM'); } } } } // Output for Ajax. die($status_message); }