Skip to content

Commit

Permalink
MDL-84275 factor_totp: format site fullname for authenticator setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jan 21, 2025
1 parent e6c92dc commit 64d6d74
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions admin/tool/mfa/factor/totp/classes/factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OTPHP\TOTP;
use stdClass;
use core\clock;
use core\context\system;
use core\di;

/**
Expand Down Expand Up @@ -90,7 +91,7 @@ public function __construct(string $name) {
public function generate_totp_uri(string $secret): string {
global $USER, $SITE, $CFG;
$host = parse_url($CFG->wwwroot, PHP_URL_HOST);
$sitename = str_replace(':', '', $SITE->fullname);
$sitename = str_replace(':', '', format_string($SITE->fullname, true, ['context' => system::instance()]));
$issuer = $sitename.' '.$host;
$totp = TOTP::create($secret, clock: $this->clock);
$totp->setLabel($USER->username);
Expand Down Expand Up @@ -190,13 +191,15 @@ public function setup_factor_form_definition_after_data(MoodleQuickForm $mform):
$secret = wordwrap($secret, 4, ' ', true) . '</code>';
$secret = \html_writer::tag('code', $secret);

$sitefullname = format_string($SITE->fullname, true, ['context' => system::instance()]);

$manualtable = new \html_table();
$manualtable->id = 'manualattributes';
$manualtable->attributes['class'] = 'generaltable table table-bordered table-sm w-auto';
$manualtable->attributes['style'] = 'width: auto;';
$manualtable->data = [
[get_string('setupfactor:key', 'factor_totp'), $secret],
[get_string('setupfactor:account', 'factor_totp'), "$SITE->fullname ($USER->username)"],
[get_string('setupfactor:account', 'factor_totp'), "{$sitefullname} ({$USER->username})"],
[get_string('setupfactor:mode', 'factor_totp'), get_string('setupfactor:mode:timebased', 'factor_totp')],
];

Expand Down

0 comments on commit 64d6d74

Please sign in to comment.