Skip to content

Commit

Permalink
IN-200 Users logged out while using PROD
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrockweilercgi committed Apr 27, 2021
1 parent 2f0de33 commit 72c6298
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/production/simplesamlphp_auth.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ role:
register_users: true
allow:
set_drupal_pwd: false
default_login: false
default_login: true
default_login_roles:
administrator: administrator
administrator: authenticated
default_login_users: '1'
logout_goto_url: 'https://work.epa.gov'
user_register_original: null
Expand Down
40 changes: 40 additions & 0 deletions docroot/themes/custom/epa_intranet/epa_intranet.theme
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Drupal\Core\Url;

/**
* Implements hook_theme_suggestions_HOOK_alter() for form templates.
* @param array $suggestions
Expand Down Expand Up @@ -102,6 +104,44 @@ function epa_intranet_preprocess_views_view_table(&$variables) {
}
}

/**
* Overwrite login links to include the current destination
* @param $variables
*/
function epa_intranet_preprocess_menu(&$variables) {
$routes = [
'user.login',
'user.logout'
];
$variables['#cache']['contexts'][] = 'url.query_args:destination';
$renderer = \Drupal::service('renderer');
$renderer->addCacheableDependency($variables, \Drupal::service('path.current')->getPath());
foreach ($variables['items'] as &$key) {
$url = $key['url'];
if ($url->isRouted() && in_array($url->getRouteName(), $routes)) {
$base = \Drupal::request()->getSchemeAndHttpHost();
// Get current path.
$current = \Drupal::service('path.current')->getPath();
if ($url->getRouteName() == 'user.login') {

$productionSplitConfig = \Drupal::config('config_split.config_split.production_config');
// Check if we are in Production
if (isset($productionSplitConfig) && $productionSplitConfig->get('status')) {
//@todo update /saml_login to use the path from route: simplesamlphp_auth.saml_login
$uriString = $base . '/saml_login?destination=' . $current;
} else {
$uriString = $base . '/user/login?destination=' . $current;
}
} else {
$uriString = $base . '/user/logout?destination=' . $current;
}
$newUrl = Url::fromUri($uriString);
$key['url'] = $newUrl;
}
}
}


function epa_intranet_preprocess_page(&$variables) {
// Load correct Hero revision for page
if (isset($variables['node'])) {
Expand Down

0 comments on commit 72c6298

Please sign in to comment.