reverted: --- b/src/Form/BasicDisable.php +++ a/src/Form/BasicDisable.php @@ -134,7 +134,6 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $user = User::load($this->currentUser()->id()); $storage = $form_state->getStorage(); - /** @var \Drupal\user\UserInterface $account */ $account = $storage['account']; // Allow administrators to disable TFA for another account. if ($account->id() != $user->id() && $user->hasPermission('administer users')) { @@ -154,16 +153,15 @@ $storage = $form_state->getStorage(); $values = $form_state->getValues(); - /** @var \Drupal\user\UserInterface $account */ $account = $storage['account']; if ($values['op'] === $values['cancel']) { + drupal_set_message($this->t('TFA disable canceled.')); - $this->messenger()->addMessage($this->t('TFA disable canceled.')); $form_state->setRedirect('tfa.overview', ['user' => $account->id()]); return; } // Delete all user data. + $this->deleteUserData('tfa', null, $account->id(), $this->userData); - $this->deleteUserData('tfa', NULL, $account->id(), $this->userData); \Drupal::logger('tfa')->notice('TFA disabled for user @name UID @uid', [ '@name' => $account->getAccountName(), @@ -174,7 +172,7 @@ $params = ['account' => $account]; \Drupal::service('plugin.manager.mail')->mail('tfa', 'tfa_disabled_configuration', $account->getEmail(), $account->getPreferredLangcode(), $params); + drupal_set_message($this->t('TFA has been disabled.')); - $this->messenger()->addMessage($this->t('TFA has been disabled.')); $form_state->setRedirect('tfa.overview', ['user' => $account->id()]); } @@ -182,7 +180,7 @@ * {@inheritdoc} */ public function cancelForm(array &$form, FormStateInterface $form_state) { + drupal_set_message('TFA Disable cancelled.', 'warning'); - $this->messenger()->addWarning('TFA Disable cancelled.'); $form_state->setRedirect('tfa.overview', ['user' => $this->currentUser()->id()]); } reverted: --- b/src/Form/BasicSetup.php +++ a/src/Form/BasicSetup.php @@ -193,7 +193,7 @@ */ public function cancelForm(array &$form, FormStateInterface $form_state) { $account = $form['account']['#value']; + drupal_set_message('TFA setup canceled.', 'warning'); - $this->messenger()->addWarning('TFA setup canceled.'); $form_state->setRedirect('tfa.overview', ['user' => $account->id()]); } @@ -232,8 +232,8 @@ // Plugin form submit. $setup_class = $storage[$method]; if (!$setup_class->submitForm($form, $form_state)) { + drupal_set_message($this->t('There was an error during TFA setup. Your + settings have not been saved.'), 'error'); - $this->messenger()->addError($this->t('There was an error during TFA setup. Your - settings have not been saved.')); $form_state->setRedirect('tfa.overview', ['user' => $account->id()]); return; } @@ -244,7 +244,7 @@ return; } // Else, setup complete and return to overview page. + drupal_set_message(t('TFA setup complete.')); - $this->messenger()->addMessage($this->t('TFA setup complete.')); $form_state->setRedirect('tfa.overview', ['user' => $account->id()]); // Log and notify if this was full setup. @@ -323,7 +323,7 @@ $count = count($storage['steps_left']); $output .= ' ' . \Drupal::translation()->formatPlural($count, 'One setup step remaining.', '@count TFA setup steps remain.', ['@count' => $count]); if ($output) { + drupal_set_message($output); - $this->messenger()->addMessage($output); } // Set next step and mark form for rebuild. reverted: --- b/src/Form/SettingsForm.php +++ a/src/Form/SettingsForm.php @@ -422,7 +422,7 @@ $message = $this->t('Email settings missing. If this is the first time you are seeing this error after upgrading the TFA module, then please make sure you have run the required @update_link function.', [ '@update_link' => Link::createFromRoute('update', 'system.status')->toString(), ]); + drupal_set_message($message, 'error'); - $this->messenger()->addError($message); } $form['mail'] = [ '#type' => 'vertical_tabs', @@ -567,7 +567,7 @@ */ protected function dataEmptyCheck($data, $message) { if (empty($data)) { + drupal_set_message($this->t($message), 'error'); - $this->messenger()->addError($this->t($message)); return TRUE; } diff -u b/src/Form/TfaLoginForm.php b/src/Form/TfaLoginForm.php --- b/src/Form/TfaLoginForm.php +++ b/src/Form/TfaLoginForm.php @@ -115,7 +115,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('flood'), - $container->get('entity.manager')->getStorage('user'), + $container->get('entity_type.manager')->getStorage('user'), $container->get('user.auth'), $container->get('renderer'), $container->get('plugin.manager.tfa.validation'), @@ -190,7 +190,7 @@ $user = $this->tfaContext->getUser(); if ($this->tfaContext->pluginAllowsLogin()) { $this->tfaContext->doUserLogin(); - $this->messenger()->addMessage('You have logged in on a trusted browser.'); + drupal_set_message('You have logged in on a trusted browser.'); $form_state->setRedirect(''); } else { only in patch2: unchanged: --- a/src/Plugin/TfaLogin/TfaTrustedBrowser.php +++ b/src/Plugin/TfaLogin/TfaTrustedBrowser.php @@ -2,7 +2,6 @@ namespace Drupal\tfa\Plugin\TfaLogin; -use Drupal\Component\Utility\Crypt; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\encrypt\EncryptionProfileManagerInterface; @@ -116,7 +115,7 @@ class TfaTrustedBrowser extends TfaBasePlugin implements TfaLoginInterface, TfaV * Base64 encoded browser id. */ protected function generateBrowserId() { - $id = base64_encode(Crypt::randomBytes(32)); + $id = base64_encode(random_bytes(32)); return strtr($id, ['+' => '-', '/' => '_', '=' => '']); } only in patch2: unchanged: --- a/src/TfaRandomTrait.php +++ b/src/TfaRandomTrait.php @@ -2,8 +2,6 @@ namespace Drupal\tfa; -use Drupal\Component\Utility\Crypt; - /** * Trait TfaRandomTrait for generating cryptographically secure random data. * @@ -79,7 +77,7 @@ trait TfaRandomTrait { for ($i = 0; $i < $length; $i++) { do { // Find a secure random number within the range needed. - $index = ord(Crypt::randomBytes(1)); + $index = ord(random_bytes(1)); } while ($index > $len); // Each iteration, pick a random character from the