diff -ruN a/simple_pass_reset.module b/simple_pass_reset.module --- a/simple_pass_reset.module 2026-06-29 12:22:15.117028898 +0530 +++ b/simple_pass_reset.module 2026-06-29 12:22:15.120028889 +0530 @@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Url; +use Drupal\user\Entity\User; /** * Implements hook_form_FORM_ID_alter(). @@ -78,12 +80,37 @@ } // Load the user account afresh and finalize the login. // @see user_login_submit() - $account = \Drupal::entityTypeManager()->getStorage('user')->load($values['uid']); + //$account = \Drupal::entityTypeManager()->getStorage('user')->load($values['uid']); + // Load the user entity. + $account = User::load($values['uid']); user_login_finalize($account); \Drupal::logger('user')->notice(t('User @name used one-time login link.', ['@name' => $values['name']])); - if (empty($form_state->getRedirect())) { - $form_state->setRedirect('user.page'); + $returnTo = \Drupal::request()->query->get('ReturnTo'); + //$session = \Drupal::request()->getSession(); + //$session_returnTo = $session->get('returnTo'); + //\Drupal::logger('simple_pass_reset/module')->info($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) { + if(getRememberMeStatus()){ + $currentUser = \Drupal::currentUser(); + drupalauth4ssp_set_user_cookie($currentUser ); + $form_state->setRedirectUrl(Url::fromUri($returnTo)); + }else{ + $session = \Drupal::request()->getSession(); + $session->set('returnTo', $returnTo); + } + } + } + else if (empty($form_state->getRedirect())) { + $url = Url::fromRoute(''); + $form_state->setRedirectUrl($url); + //$form_state->setRedirect('user.page'); } } } @@ -102,3 +129,4 @@ $implementations['simple_pass_reset'] = $group; } } + diff -ruN a/src/Controller/User.php b/src/Controller/User.php --- a/src/Controller/User.php 2026-06-29 12:22:15.117028898 +0530 +++ b/src/Controller/User.php 2026-06-29 12:22:15.120028889 +0530 @@ -4,6 +4,7 @@ use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Url; /** * Alter User Reset password page. @@ -18,16 +19,48 @@ $user = \Drupal::entityTypeManager()->getStorage('user')->load($uid); $account = \Drupal::currentUser(); + $session = \Drupal::request()->getSession(); + $returnTo = $session->get('returnTo'); + $match=false; + if (!empty($returnTo)) { + \Drupal::logger('simple_pass_reset/controller')->notice($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) { + $match=true; + } + } + \Drupal::logger('simple_pass_reset/controller')->notice($match); // The current user is already logged in. if ($account->isAuthenticated() && $account->id() == $uid) { user_logout(); // We need to begin the redirect process again because logging out will // destroy the session. - return $this->redirect('user.reset', [ - 'uid' => $uid, - 'timestamp' => $timestamp, - 'hash' => $hash, - ]); + // return $this->redirect('user.reset', [ + // 'uid' => $uid, + // 'timestamp' => $timestamp, + // 'hash' => $hash, + // ]); + + if (!empty($returnTo) && $match) { + return $this->redirect('user.reset', [ + 'uid' => $uid, + 'timestamp' => $timestamp, + 'hash' => $hash, + 'ReturnTo' => $returnTo + ]); + + } else { + return $this->redirect('user.reset', [ + 'uid' => $uid, + 'timestamp' => $timestamp, + 'hash' => $hash, + ]); + } + } $formObject = \Drupal::service('entity_type.manager') ->getFormObject('user', 'default')