Add User::getEnabledMultifactorMethods()
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 2 Nov 2020 14:04:40 +0000 (15:04 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 16 Nov 2020 16:25:03 +0000 (17:25 +0100)
com.woltlab.wcf/templates/accountSecurity.tpl
wcfsetup/install/files/lib/data/user/User.class.php
wcfsetup/install/files/lib/page/AccountSecurityPage.class.php

index 20a3954b47bfcd065b24260bff2ebe17df9fd04d..ffd304234a70031df11e9c8ea20489197c3f21b3 100644 (file)
                                
                                <div>
                                        <div class="containerHeadline">
-                                               <h3>{lang}wcf.user.security.multifactor.{$method->objectType}{/lang}</h3>
+                                               <h3>
+                                                       {lang}wcf.user.security.multifactor.{$method->objectType}{/lang}
+                                                       
+                                                       {if $enabledMultifactorMethods[$method->objectTypeID]|isset}
+                                                               <span class="badge green">
+                                                                       {lang}wcf.user.security.multifactor.active{/lang}
+                                                               </span>
+                                                       {/if}
+                                               </h3>
                                                
                                                {$method->getProcessor()->getStatusText($__wcf->user)}
                                        </div>
index 8bc0e834c6743cb81f8b43ac966fa22c07b053c3..873c648d44eb4762c64c1a35aa4270e896fb3afd 100644 (file)
@@ -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
         */
index b9711c288254d218c45a8f3c342b5baf08f06834..e1b3296c4f376f91ba2a663b74d62e7cfa533f37 100644 (file)
@@ -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,
                ]);
        }