Hello everybody!
For my Drupal website I need to check if TFA is set. If it is not set I would like to make the page display only the message that TFA is not set up and not the rest of the content. My idea is to get the isReady() boolean in the $_SESSION and then use it in my twig to check before displaying parts of the page however I seem to have some issues with this.
In the TfaLoginForm.php I have the following code:
public function loginWithoutTfa(FormStateInterface $form_state) {
// User may be able to skip TFA, depending on module settings and number of
// prior attempts.
$remaining = $this->tfaContext->remainingSkips();
if ($remaining) {
$user = $this->tfaContext->getUser();
$tfa_setup_link = Url::fromRoute('tfa.overview', [
'user' => $user->id(),
])->toString();
drupal_set_message($this->t('You are required to setup two-factor authentication <a href="@link">here.</a> You have @remaining attempts left after this you will be unable to login.', [
'@remaining' => $remaining - 1,
'@link' => $tfa_setup_link,
]), 'error');
$this->tfaContext->hasSkipped();
$this->tfaContext->doUserLogin();
$form_state->setRedirect('<front>');
$_SESSION['lists']['CheckTFA'] = $this->tfaContext->isReady(); <--- The line I added.
}
then in my theme hook I assign this value to the $variables array like this:
$variables["check"] = $_SESSION['lists']['CheckTFA'];
and I use it in the twig like this:
{% if check %}
This does not do anything and when I try to only display it on the page nothing shows up.
Can someone give a look and help me with what I am doing wrong?
Viktor