You are here

function drupalauth4ssp_user_login_submit in DrupalAuth for SimpleSAMLphp 8

Sets redirect upon successful login.

1 string reference to 'drupalauth4ssp_user_login_submit'
drupalauth4ssp_form_user_login_form_alter in ./drupalauth4ssp.module
Implements hook_form_FORM_ID_alter().

File

./drupalauth4ssp.module, line 157
DrupalAuth For simpleSAMLphp module.

Code

function drupalauth4ssp_user_login_submit($form, \Drupal\Core\Form\FormStateInterface $form_state) {

  // If the ReturnTo URL is present, send the user to the URL.
  $returnTo = \Drupal::request()->query
    ->get('ReturnTo');
  if (!empty($returnTo)) {
    $returnto_list = \Drupal::service('config.factory')
      ->get('drupalauth4ssp.settings')
      ->get('returnto_list');
    $path_matcher = \Drupal::service('path.matcher');

    // Check the ReturnTo if it's in the allowed list.
    $match = $path_matcher
      ->matchPath($returnTo, $returnto_list);
    if ($match) {
      $form_state
        ->setRedirectUrl(Url::fromUri($returnTo));
    }
  }
}