From: Tim Düsterhus Date: Mon, 2 Nov 2020 14:04:40 +0000 (+0100) Subject: Add User::getEnabledMultifactorMethods() X-Git-Tag: 5.4.0_Alpha_1~555^2~53^2~28 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fdfca05594c7f37f544ffaee9d349545f0d4a99b;p=GitHub%2FWoltLab%2FWCF.git Add User::getEnabledMultifactorMethods() --- diff --git a/com.woltlab.wcf/templates/accountSecurity.tpl b/com.woltlab.wcf/templates/accountSecurity.tpl index 20a3954b47..ffd304234a 100644 --- a/com.woltlab.wcf/templates/accountSecurity.tpl +++ b/com.woltlab.wcf/templates/accountSecurity.tpl @@ -14,7 +14,15 @@
-

{lang}wcf.user.security.multifactor.{$method->objectType}{/lang}

+

+ {lang}wcf.user.security.multifactor.{$method->objectType}{/lang} + + {if $enabledMultifactorMethods[$method->objectTypeID]|isset} + + {lang}wcf.user.security.multifactor.active{/lang} + + {/if} +

{$method->getProcessor()->getStatusText($__wcf->user)}
diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index 8bc0e834c6..873c648d44 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -5,6 +5,8 @@ use wcf\data\language\Language; use wcf\data\user\group\UserGroup; use wcf\data\DatabaseObject; use wcf\data\IUserContent; +use wcf\data\object\type\ObjectType; +use wcf\data\object\type\ObjectTypeCache; use wcf\data\user\option\UserOption; use wcf\system\cache\builder\UserOptionCacheBuilder; use wcf\system\language\LanguageFactory; @@ -690,6 +692,27 @@ final class User extends DatabaseObject implements IPopoverObject, IRouteControl return REGISTER_ACTIVATION_METHOD & self::REGISTER_ACTIVATION_USER; } + /** + * Returns the multi factor methods the user set up. + * + * @return ObjectType[] + * @since 5.4 + */ + public function getEnabledMultifactorMethods(): array { + $sql = "SELECT * + FROM wcf".WCF_N."_user_multifactor + WHERE userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$this->userID]); + + $methods = []; + while ($row = $statement->fetchArray()) { + $methods[$row['setupID']] = ObjectTypeCache::getInstance()->getObjectType($row['objectTypeID']); + } + + return $methods; + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php b/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php index b9711c2882..e1b3296c4f 100644 --- a/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php +++ b/wcfsetup/install/files/lib/page/AccountSecurityPage.class.php @@ -32,6 +32,11 @@ class AccountSecurityPage extends AbstractPage { */ private $multifactorMethods; + /** + * @var int[] + */ + private $enabledMultifactorMethods; + /** * @inheritDoc */ @@ -45,6 +50,9 @@ class AccountSecurityPage extends AbstractPage { }); $this->multifactorMethods = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.multifactor'); + $this->enabledMultifactorMethods = array_flip(array_map(function (ObjectType $o) { + return $o->objectTypeID; + }, WCF::getUser()->getEnabledMultifactorMethods())); } /** @@ -56,6 +64,7 @@ class AccountSecurityPage extends AbstractPage { WCF::getTPL()->assign([ 'activeSessions' => $this->activeSessions, 'multifactorMethods' => $this->multifactorMethods, + 'enabledMultifactorMethods' => $this->enabledMultifactorMethods, ]); }