Skip to content

Commit

Permalink
[SD-375] Added dependency injection for request stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
MdNadimHossain committed Oct 30, 2024
1 parent d628887 commit a9f0203
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions modules/tide_tfa/src/Controller/TideTfaUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,38 @@
use Drupal\prlp\Controller\PrlpController;
use Drupal\tfa\Controller\TfaUserControllerBase;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Custom controller to override the TfaUserControllerBase.
*/
class TideTfaUserController extends TfaUserControllerBase {

/**
* The request stack service.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
// Get the parent instance with inherited dependencies.
$instance = parent::create($container);
$instance->requestStack = $container->get('request_stack');

return $instance;
}

/**
* {@inheritdoc}
*/
public function doResetPassLogin($uid, $timestamp, $hash, $request = NULL) {
// Ensure a valid request object.
if (!$request) {
$request = \Drupal::request();
$request = $this->requestStack->getCurrentRequest();
}

// Check if the PRLP module is enabled.
Expand All @@ -41,8 +60,8 @@ public function doResetPassLogin($uid, $timestamp, $hash, $request = NULL) {
$user = $this->userStorage->load($uid);
$this->setUser($user);

// Let Drupal core deal with the one time login,
// if Tfa is not enabled or
// Let Drupal core deal with the one-time login,
// if TFA is not enabled or
// current user can skip TFA while resetting password.
if ($this->isTfaDisabled() || $this->canSkipPassReset()) {
// Use PRLP's resetPassLogin instead of the core function.
Expand Down Expand Up @@ -76,7 +95,7 @@ public function doResetPassLogin($uid, $timestamp, $hash, $request = NULL) {
if ($tfa_ready) {
$this->session->migrate();
$token = Crypt::randomBytesBase64(55);
$request ? $request->getSession()->set('pass_reset_' . $uid, $token) : $_SESSION['pass_reset_' . $uid] = $token;
$request->getSession()->set('pass_reset_' . $uid, $token);

$this->logger->notice('User %name used one-time login link at time %timestamp.', [
'%name' => $user->getDisplayName(),
Expand Down

0 comments on commit a9f0203

Please sign in to comment.