diff --git a/factor/token/classes/factor.php b/factor/token/classes/factor.php index 360af55b..a6374461 100644 --- a/factor/token/classes/factor.php +++ b/factor/token/classes/factor.php @@ -144,10 +144,14 @@ public function global_definition_after_data($mform) { // First thing, we need to decide on whether we should show the checkbox. $noproperty = !property_exists($SESSION, 'tool_mfa_factor_token'); $nostate = $this->get_state() !== \tool_mfa\plugininfo\factor::STATE_PASS; + // We shouldn't show if the current factor does not give points. Nothing to "trust" in that case. + $factor = \tool_mfa\plugininfo\factor::get_next_user_factor(); + $weight = $factor->get_weight(); + // We also shouldn't display if the duration for the user is 0; + $expiryconfig = is_siteadmin() ? 'adminexpiry' : 'expiry'; + $expiry = get_config('factor_token', $expiryconfig); - if ($noproperty && $nostate) { - $expiryconfig = is_siteadmin() ? 'adminexpiry' : 'expiry'; - $expiry = get_config('factor_token', $expiryconfig); + if ($noproperty && $nostate && $weight !== 0 && $expiry !== 0) { $expirystring = format_time($expiry); $mform->addElement('advcheckbox', 'factor_token_trust', '', get_string('form:trust', 'factor_token', $expirystring)); $mform->setType('factor_token_trust', PARAM_BOOL); @@ -164,9 +168,11 @@ public function global_definition_after_data($mform) { public function global_submit($data) { global $SESSION; - // Store any kind of response here, we shouldnt show again. - $trust = $data->factor_token_trust; - $SESSION->tool_mfa_factor_token = $trust; + if (property_exists($data, "factor_token_trust")) { + // Store any kind of response here, we shouldnt show again. + $trust = $data->factor_token_trust; + $SESSION->tool_mfa_factor_token = $trust; + } } /**