Skip to content

Commit

Permalink
SUPP0RT-821: Fixed handling of default login method
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Jan 3, 2023
1 parent 74fc4d5 commit 1a1ec45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ services:
- '@entity_field.manager'
- '@messenger'
- '@request_stack'
- '@path.current'
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
Expand Down Expand Up @@ -63,16 +64,24 @@ class Helper {
*/
protected $moduleHandler;

/**
* The current path stack.
*
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected $currentPathStack;

/**
* Constructor.
*/
public function __construct(Settings $settings, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, EntityFieldManager $entity_field_manager, MessengerInterface $messenger, RequestStack $requestStack) {
public function __construct(Settings $settings, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, EntityFieldManager $entity_field_manager, MessengerInterface $messenger, RequestStack $requestStack, CurrentPathStack $currentPathStack) {
$this->config = $settings->getConfig(SettingsForm::SETTINGS_NAME);
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
$this->messenger = $messenger;
$this->requestStack = $requestStack;
$this->currentPathStack = $currentPathStack;
}

/**
Expand Down Expand Up @@ -125,6 +134,13 @@ public function alterForm(&$form, FormStateInterface $form_state, $form_id) {
*/
public function preprocessBlock(array &$variables) {
if ('userlogin' === ($variables['elements']['#id'] ?? NULL)) {
// Ignore default login method when resetting password.
// Note: CurrentPathStack::getPath() claims to return the path without
// leading slashes, but seems to return it with a leading slash.
if (preg_match('@^/?user/(reset|password)@', $this->currentPathStack->getPath())) {
return;
}

$defaultLoginMethod = $this->config->get('default_login_method');
switch ($defaultLoginMethod) {
case 'oidc':
Expand Down

0 comments on commit 1a1ec45

Please sign in to comment.