You are here

function constant_contact_check_login in Constant Contact 7.3

Authenticate with the API.

This is used for the admin settings page to check the details they entered.

1 string reference to 'constant_contact_check_login'
constant_contact_menu in ./constant_contact.module
Implements hook_menu().

File

./constant_contact.module, line 252

Code

function constant_contact_check_login() {
  module_load_include('php', 'constant_contact', 'class.cc');
  $username = isset($_GET['username']) ? strip_tags($_GET['username']) : '';
  $password = isset($_GET['password']) ? strip_tags($_GET['password']) : '';
  if (trim($username) != '' && strpos($username, ' ') !== FALSE) {
    echo "<div style='color:red;'>Usernames with a space in them are NOT supported by the constant contact API, please change your username and try again.</div>";
  }
  elseif (trim($username) != '' && trim($password) != '') {
    $cc = new cc($username, $password);
    if (is_object($cc) && $cc
      ->get_service_description()) {

      // we have successfully connected
      echo '<div class="cc_auth_res" style="color:green;">Your login details appear to be ok, please click the "Save configuration" button to proceed with the module setup</div>';
    }
    elseif ($cc->http_response_code) {

      // oops, problem occured and we have an error code
      echo "<div' style='color:red;'>" . $cc
        ->http_get_response_code_error($cc->http_response_code) . "</div>";
    }
    else {
      echo "<div style='color:red;'>Sorry there has been an unknown error</div>";
    }
  }
}