You are here

function cas_test_login in CAS 6.3

Same name and namespace in other branches
  1. 7 tests/cas_test.module \cas_test_login()

Initiate a login request.

Set the 'cas_test_cas_user' variable to an associative array containing:

  • 'name': CAS username.
  • 'attributes': (optional) Any other name-value pairs to be returned by the CAS server.
1 string reference to 'cas_test_login'
cas_test_menu in tests/cas_test.module
Implements hook_menu().

File

tests/cas_test.module, line 98
Dummy module implementing a CAS Server.

Code

function cas_test_login() {

  // Get the service and make a ticket.
  $service = $_REQUEST['service'];
  $cas_user = variable_get('cas_test_cas_user', '');
  if ($cas_user) {
    if (!is_array($cas_user)) {
      $cas_user = array(
        'name' => $cas_user,
        'attributes' => array(),
      );
    }

    // Generate a ticket and redirect to the service URL with the login ticket.
    $ticket = _cas_test_ticket_generate($service, $cas_user);

    // Force redirection.
    unset($_REQUEST['destination']);
    drupal_goto($service, array(
      'ticket' => $ticket,
    ));
  }
  elseif (isset($_GET['gateway']) && $_GET['gateway'] == 'true') {

    // We were not able to log in the user, so redirect to the service URL.
    // Force redirection.
    unset($_REQUEST['destination']);
    drupal_goto($service);
  }
  else {

    // No CAS name was provided, print an error message.
    print "Warning: No CAS name provided.\n";
    exit;
  }
}