mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
Refactor account TOTP action rendering and status queries (#1198)
As suggested by @cboltz in #1188 (comment) and #1188 (comment), move TOTP action HTML out of both AdminHandler and MailboxHandler into a shared Smarty partial.
This commit is contained in:
1 parent
fda66026ca
commit
748e3ea121
6 files changed
+93
-41
No files matched your search
+9
-19
@@ -91,13 +91,16 @@ class AdminHandler extends PFAHandler
|
||||
'created' => self::pacol(0, 0, 0, 'ts', 'created' , ''),
|
||||
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified' , ''),
|
||||
);
|
||||
# Admin-side TOTP management
|
||||
# Compute status in the account query without exposing the secret or querying each row.
|
||||
if (Config::bool('totp') && !$this->new) {
|
||||
$this->struct['totp_action'] = self::pacol(
|
||||
0, 1, 0, 'html', 'pUsersMenu_totp', '', '',
|
||||
0, 1, 0, 'totp', 'pUsersMenu_totp', '', false,
|
||||
array(),
|
||||
/*not_in_db*/ 1,
|
||||
/*dont_write_to_db*/ 1
|
||||
/*not_in_db*/ 0,
|
||||
/*dont_write_to_db*/ 1,
|
||||
/*select*/ "CASE WHEN active = '" . db_get_boolean(true) . "' AND totp_secret IS NOT NULL " .
|
||||
"AND LENGTH(totp_secret) > 0 AND NOT (LENGTH(totp_secret) = 1 AND totp_secret = '0') " .
|
||||
"THEN 1 ELSE 0 END AS totp_action"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -196,21 +199,8 @@ class AdminHandler extends PFAHandler
|
||||
if ($row['superadmin']) {
|
||||
$db_result[$key]['domain_count'] = Config::lang('super_admin');
|
||||
}
|
||||
# Render TOTP action
|
||||
if (isset($this->struct['totp_action']) && is_string($row['username'])) {
|
||||
|
||||
$totp = new TotpPf('admin', new Login('admin'));
|
||||
$has_totp = $totp->usesTOTP($row['username']);
|
||||
|
||||
if ($has_totp) {
|
||||
$db_result[$key]['totp_action'] =
|
||||
'<button type="submit" name="reset_totp" value="1" class="btn btn-warning btn-sm">' .
|
||||
htmlspecialchars(Config::lang('pUsersMenu_reset_totp'), ENT_QUOTES, 'UTF-8') .
|
||||
'</button>';
|
||||
} else {
|
||||
$db_result[$key]['totp_action'] =
|
||||
htmlspecialchars(Config::lang('pUsersMenu_no_totp_set'), ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
if (isset($row['totp_action'])) {
|
||||
$db_result[$key]['totp_action'] = (bool)$row['totp_action'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user