You are here

function generate_login_text in Shibboleth Authentication 5.3

Same name and namespace in other branches
  1. 5.2 shib_auth.module \generate_login_text()
  2. 6 shib_auth.module \generate_login_text()
  3. 6.2 shib_auth.module \generate_login_text()
  4. 6.3 shib_auth.module \generate_login_text()

Generate the login text in HTML format using the 't' function @returns HTML text of the login form

2 calls to generate_login_text()
shib_auth_block in ./shib_auth.module
Generate the HTML text for the shib_auth login block
shib_auth_form_alter in ./shib_auth.module
Alters forms for the shibboleth authentication module.

File

./shib_auth.module, line 144
Provides user authentication with Shibboleth (both v1.3 and v2.0) as well as some authorisation features (automatic role assignment base on Shibboleth attributes).

Code

function generate_login_text() {
  global $base_url, $user;
  if (!$user->uid) {
    $handler_url = variable_get('shib_auth_handler_url', '/Shibboleth.sso');
    $handler_protocol = variable_get('shib_auth_handler_protocol', 'https');
    $wayf_uri = variable_get('shib_auth_wayf_uri', '/WAYF/HREF');

    // If the WAYF's URI doesn't start with slash then extend it
    if (!ereg('^/', $wayf_uri)) {
      $wayf_uri = '/' . $wayf_uri;
    }
    $handler = '';
    $block_content = '';
    if (ereg("^http[s]{0,1}://", $handler_url)) {

      // If handlerURL is an absolute path
      $handler = $handler_url . $wayf_uri;
    }
    else {

      // Else, if the handlerURL is a relative path
      // If the WAYF's URI doesn't start with slash then extend it
      if (!ereg("^/", $handler_url)) {
        $handler_url = "/" . $handler_url;
      }
      $handler = $handler_protocol . '://' . $_SERVER['HTTP_HOST'] . $handler_url . $wayf_uri;
    }

    //$actualLocation: the path where the Shibboleth should return
    $actual_location = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . request_uri();

    // If there is no session yet then we should put the login text into the block
    $block_content .= '<p><b><a href=' . $handler . '?target=' . $actual_location . '>' . variable_get('auth_link_text', t('Click here to login via Shibboleth!')) . '</a></b></p>';
    return $block_content;
  }
}