You are here

function shib_auth_custom_form in Shibboleth Authentication 7.4

Same name and namespace in other branches
  1. 6.4 shib_auth.module \shib_auth_custom_form()

Displays custom form if either customization or consent options are enabled.

If any customization or consent option is enabled, the custom form will show up before registering and forces the user to accept user consent and define username and/or email address (pre-filling fields with the data coming from the IdP).

Parameters

string $umail_single: The first email address of the user from the IdP.

string $uname: Username received from IdP.

1 call to shib_auth_custom_form()
shib_auth_init in ./shib_auth.module
Creates a new user, if necessary, based on information from the handler.

File

./shib_auth.module, line 617
Drupal Shibboleth authentication module.

Code

function shib_auth_custom_form($umail_single = NULL, $uname = NULL) {

  // Avoid warnings:
  $custom_username = $custom_mail = '';
  if (isset($_POST['op']) && $_POST['op'] == t('Cancel')) {
    shib_auth_cancel_custom();
  }

  // Check if any of the customization options are enabled.
  if (shib_auth_config('enable_custom_mail') || $umail_single && shib_auth_config('define_username') || (shib_auth_config('enable_custom_mail') || $umail_single) && shib_auth_config('terms_accept')) {

    // If there already is a POST-ed form, save received values as a variable.
    if (isset($_POST['form_id']) && $_POST['form_id'] == 'shib_auth_custom_data') {
      if (!empty($_POST['custom_mail'])) {
        $custom_mail = filter_xss($_POST['custom_mail']);
      }
      if (!empty($_POST['custom_username'])) {
        $custom_username = filter_xss($_POST['custom_username']);
      }
      if (!empty($_POST['accept'])) {
        $consent_accepted = filter_xss($_POST['accept']);
      }
    }

    // If the consent is accepted or it isn't configured.
    if (!shib_auth_config('terms_accept') || !empty($consent_accepted) && shib_auth_config('terms_accept')) {

      // ****** CUSTOM MAIL **********
      // if the user provided the custom mail string on the custom data form,
      // and it is not empty.
      if ($custom_mail) {
        shib_auth_custom_mail($uname, $custom_username, $custom_mail);
      }
      elseif (shib_auth_config('define_username') && !empty($custom_username)) {
        shib_auth_custom_username($uname, $custom_username, $umail_single);
      }
      elseif (shib_auth_config('terms_accept') && !empty($consent_accepted)) {

        // Register user.
        shib_auth_save_authmap($uname, $uname, $umail_single);
      }
      else {
        shib_auth_goto_custom_form();
      }
    }
    else {
      shib_auth_goto_custom_form();
    }

    // If everything was fine, the user is logged in, and redirected to the
    // page, which she wanted to open before the auth process had been
    // initiated.
    shib_auth_submit_redirect();
    return TRUE;
  }
  else {
    return FALSE;
  }
}