Skip to content

Commit

Permalink
Merge pull request #3165 from CityOfBoston/post-d10-cleanup
Browse files Browse the repository at this point in the history
(develop) Post d10 cleanup
  • Loading branch information
davidrkupton authored Aug 22, 2023
2 parents 01215a5 + 670e167 commit c990619
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
34 changes: 33 additions & 1 deletion docroot/modules/custom/bos_core/includes/samlauth.extensions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,24 @@ function bos_core_form_samlauth_configure_form_alter(&$form, $form_state, $form_
'#attributes' => ["placeholder" => "sn lastname"],
'#type' => 'textfield',
];

$form["#submit"][] = "samlauth_extensions_form_submit";
$form["saml_login_logout"]["allow_local_login"] = [
"#type" => "checkbox",
'#default_value' => $config->get("allow_local_login") ?: 0,
'#title' => Markup::create("Allow local logins"),
'#description' => Markup::create("When selected users can login with a local account at user/login. Deselected means SSO only."),
'#weight' => -11,
];
$form["saml_login_logout"]["login_menu_item_title"]["#weight"] = -10;
$form["saml_login_logout"]["login_menu_item_instructions"] = [
"#default_value" => $config->get("login_menu_item_instructions") ?: "",
'#description' => Markup::create("Provide some login instructions/narrative"),
'#title' => Markup::create("Login menu item instructions"),
'#type' => 'textfield',
"#weight" => -9,
];
$form["saml_login_logout"]["logout_menu_item_title"]["#weight"] = -8;
$form["saml_login_logout"]["logout_different_user"]["#weight"] = -7;
$form_state->setRebuild(true);
}

Expand All @@ -49,6 +65,22 @@ function samlauth_extensions_form_submit($form, $form_state) {
$save = TRUE;
}
}
if ($form_state->hasValue("login_menu_item_instructions")) {
$newval = $form_state->getValue("login_menu_item_instructions");
$existingval = $config->get("login_menu_item_instructions") ?: "";
if ($newval !== $existingval) {
$config->set("login_menu_item_instructions", $newval);
$save = TRUE;
}
}
if ($form_state->hasValue("allow_local_login")) {
$newval = $form_state->getValue("allow_local_login");
$existingval = $config->get("allow_local_login") ?: "";
if ($newval !== $existingval) {
$config->set("allow_local_login", $newval);
$save = TRUE;
}
}
if ($save) {
$config->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(RedirectChecker $checker) {
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* The event to process.
*/
public function onLogoutRequestRedirect(RequestEvent $event) {
public function onLoginLogoutPageRequest(RequestEvent $event) {
// Get a clone of the request. During inbound processing the request
// can be altered. Allowing this here can lead to unexpected behavior.
// For example the path_processor.files inbound processor provided by
Expand All @@ -60,6 +60,18 @@ public function onLogoutRequestRedirect(RequestEvent $event) {
\Drupal::service('bos_core.redirect')->setRedirectResponse($response);
$response->send();
}
elseif ($request->getPathInfo() == "/user/login") {
$config = \Drupal::config("samlauth.authentication");
if ($config->get("allow_local_login") == 1) {
return;
}
$request_query = $request->query->all();
$url = Url::fromRoute('samlauth.saml_controller_login', [], ['absolute' => 'true']);
$url->setOption('query', (array) $url->getOption('query') + $request_query);
$response = new RedirectResponse($url->toString());
\Drupal::service('bos_core.redirect')->setRedirectResponse($response);
$response->send();
}
}

/**
Expand All @@ -69,7 +81,7 @@ public static function getSubscribedEvents() {
// This needs to run before RouterListener::onKernelRequest(), which has
// a priority of 32. Otherwise, that aborts the request if no matching
// route is found.
$events[KernelEvents::REQUEST][] = ['onLogoutRequestRedirect'];
$events[KernelEvents::REQUEST][] = ['onLoginLogoutPageRequest'];
return $events;
}

Expand Down
30 changes: 16 additions & 14 deletions docroot/themes/custom/bos_theme/bos_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -481,17 +481,29 @@ function bos_theme_preprocess_page__user__login(array &$variables) {
*/
function bos_theme_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$config = \Drupal::config("samlauth.authentication");

$form["new"] = [
"#type" => "fieldset",
"#title" => Markup::create("<h3>Login to Boston.gov</h3>"),
"#description" => Markup::create("<p>Please log in using Access Boston, or enter your Drupal username and password</p>"),
"#description" => Markup::create("<p class='intro-text supporting-text'>{$config->get('login_menu_item_instructions')}</p>"),
"#description_display" => "before",
'flexzone' => [
'#type' => 'container',
'#attributes' => [
'class' => ['g'],
'id' => 'ping-fieldset'
],
'regular' => [
'#type' => 'container',
'#attributes' => [
'class' => ['g--6'],
'id' => 'creds-wrapper'
],
"name" => $form["name"],
"pass" => $form["pass"],
"#weight" => 0
],
"actions" => array_merge($form["actions"], ["#weight" => -1, "#attributes" => ["class" => ["g--2"]]]),
'sso' => [
"#type" => 'container',
'#attributes' => [
Expand All @@ -505,29 +517,19 @@ function bos_theme_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStat
'#type' => "submit",
"#value" => Markup::create($config->get("login_menu_item_title")),
'#submit' => ["ping_submit"],
"#name" => "ping",
"#validate" => ["ping_validate"],
],
"#weight" => 1
],
'regular' => [
'#type' => 'container',
'#attributes' => [
'class' => ['g--6'],
'id' => 'creds-wrapper'
],
"name" => $form["name"],
"pass" => $form["pass"],
],
"actions" => array_merge($form["actions"], ["#attributes" => ["class" => ["g--2"]]]),
],
];
unset($form["pass"]);
unset($form["name"]);
unset($form["actions"]);
$form_state->setRebuild(TRUE);
}

/**
* Implements hook_form_alter().
*/
function ping_validate(&$form, $form_state) {
$form_state->clearErrors();
}
Expand Down
4 changes: 3 additions & 1 deletion docroot/themes/custom/bos_theme/css/bos_theme_overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ body.logged-in.toolbar-fixed .site-banner.dr {
}
#user-login-form #ping-fieldset {
align-items: center;
padding: 2px 30px 2px 2px;
flex-direction: row-reverse;
}
#user-login-form #edit-ping {
padding: 18% 0;
Expand All @@ -1664,11 +1664,13 @@ body.logged-in.toolbar-fixed .site-banner.dr {
#user-login-form #creds-wrapper {
border-left: 5px solid #333;
padding: 0 0 0 30px;
margin-left: 27px;
}
#user-login-form #edit-actions {
align-self: flex-end;
margin-bottom: 36px;
margin-left: 27px;
margin-right: 0px;
}
#user-login-form #ping-img {
width: 50%;
Expand Down

0 comments on commit c990619

Please sign in to comment.