Add usesMultifactor condition for notices
authorjoshuaruesweg <ruesweg@woltlab.com>
Sun, 22 Nov 2020 10:37:45 +0000 (11:37 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sun, 22 Nov 2020 10:37:45 +0000 (11:37 +0100)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/condition/UserMultifactorCondition.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 4e7f955338069075e990a5407a947406e14a031d..0a015a876eb649a4d5748f2181ebf16ee2e9857f 100644 (file)
                        <propertyname>trophyPoints</propertyname>
                        <minvalue>0</minvalue>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.user.multifactor</name>
+                       <definitionname>com.woltlab.wcf.condition.notice</definitionname>
+                       <classname>wcf\system\condition\UserMultifactorCondition</classname>
+                       <conditionobject>com.woltlab.wcf.user</conditionobject>
+                       <conditiongroup>general</conditiongroup>
+               </type>
                <!-- /notice conditions -->
                <!-- ad locations -->
                <type>
diff --git a/wcfsetup/install/files/lib/system/condition/UserMultifactorCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserMultifactorCondition.class.php
new file mode 100644 (file)
index 0000000..cfec88c
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+namespace wcf\system\condition;
+use wcf\data\condition\Condition;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+
+/**
+ * Condition implementation if it is the user has an active second factor.
+ * 
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2020 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Condition
+ * @since       5.4
+ */
+class UserMultifactorCondition extends AbstractSingleFieldCondition implements IContentCondition {
+       /**
+        * @inheritDoc
+        */
+       protected $label = 'wcf.user.condition.multifactor';
+       
+       /**
+        * 1 if uses multifactor checkbox is checked
+        * @var integer
+        */
+       protected $usesMultifactor = 0;
+       
+       /**
+        * 1 if uses no multifactor checkbox is checked
+        * @var integer
+        */
+       protected $usesNoMultifactor = 0;
+       
+       /**
+        * @inheritDoc
+        */
+       public function getData() {
+               if ($this->usesMultifactor || $this->usesNoMultifactor) {
+                       return [
+                               // if usesNoMultifactor is selected usesMultifactor is 0
+                               // otherwise usesNoMultifactor is 1
+                               'usesMultifactor' => $this->usesMultifactor
+                       ];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function getFieldElement() {
+               $usesMultifactorLabel = WCF::getLanguage()->get('wcf.user.condition.multifactor.usesMultifactor');
+               $usesNoMultifactorLabel = WCF::getLanguage()->get('wcf.user.condition.multifactor.usesNoMultifactor');
+               $usesMultifactorChecked = '';
+               if ($this->usesMultifactor) {
+                       $usesMultifactorChecked = ' checked';
+               }
+               
+               $usesNoMultifactorChecked = '';
+               if ($this->usesNoMultifactor) {
+                       $usesNoMultifactorChecked = ' checked';
+               }
+               
+               return <<<HTML
+<label><input type="checkbox" name="usesMultifactor" id="usesMultifactor"{$usesMultifactorChecked}> {$usesMultifactorLabel}</label>
+<label><input type="checkbox" name="usesNoMultifactor" id="usesNoMultifactor"{$usesNoMultifactorChecked}> {$usesNoMultifactorLabel}</label>
+HTML;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function readFormParameters() {
+               if (isset($_POST['usesMultifactor'])) $this->usesMultifactor = 1;
+               if (isset($_POST['usesNoMultifactor'])) $this->usesNoMultifactor = 1;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function reset() {
+               $this->usesMultifactor = $this->usesNoMultifactor = 0;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function setData(Condition $condition) {
+               $this->usesMultifactor = $condition->usesMultifactor;
+               $this->usesNoMultifactor = !$condition->usesMultifactor;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function validate() {
+               if ($this->usesMultifactor && $this->usesNoMultifactor) {
+                       $this->errorMessage = 'wcf.user.condition.multifactor.usesMultifactor.error.conflict';
+                       
+                       throw new UserInputException('usesMultifactor', 'conflict');
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function showContent(Condition $condition) {
+               return (($condition->usesMultifactor && WCF::getUser()->multifactorActive) || (!$condition->usesMultifactor && !WCF::getUser()->multifactorActive));
+       }
+}
index 994acdc89dd528ecbd83931dda2bbf5063d5d62b..37691187bf546494f2bd84df2d695e14466f1a78 100644 (file)
@@ -5092,6 +5092,10 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser"><![CDATA[Verwendet mobilen Browser]]></item>
                <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser.error.conflict"><![CDATA[„Verwendet mobilen Browser“ und „Verwendet keinen mobilen Browser“ können nicht gleichzeitig ausgewählt werden.]]></item>
                <item name="wcf.user.condition.mobileBrowser.usesNoMobileBrowser"><![CDATA[Verwendet keinen mobilen Browser]]></item>
+               <item name="wcf.user.condition.multifactor"><![CDATA[Mehrfaktor-Authentifizierung]]></item>
+               <item name="wcf.user.condition.multifactor.usesMultifactor"><![CDATA[Verwendet eine Mehrfaktor-Authentifizierung]]></item>
+               <item name="wcf.user.condition.multifactor.usesMultifactor.error.conflict"><![CDATA[„Verwendet die Mehrfaktor-Authentifizierung“ und „Verwendet keine Mehrfaktor-Authentifizierung“ können nicht gleichzeitig ausgewählt werden.]]></item>
+               <item name="wcf.user.condition.multifactor.usesNoMultifactor"><![CDATA[Verwendet keine Mehrfaktor-Authentifizierung]]></item>
                <item name="wcf.user.condition.notGroupIDs"><![CDATA[nicht in Benutzergruppen]]></item>
                <item name="wcf.user.condition.notGroupIDs.description"><![CDATA[Benutzer dürfen in keiner der ausgewählten Benutzergruppen Mitglied sein.]]></item>
                <item name="wcf.user.condition.notGroupIDs.error.groupIDsIntersection"><![CDATA[Die ausgewählten Benutzergruppen in „in Benutzergruppen“ und „nicht in Benutzergruppen“ sind widersprüchlich.]]></item>
index f440faba8fc89ef20774d27182aaeadec160ceba..a5b83397028d411447774a0ee8f4b9c511eabfba 100644 (file)
@@ -5089,6 +5089,10 @@ Open the link below to access the user profile:
                <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser"><![CDATA[Uses mobile device]]></item>
                <item name="wcf.user.condition.mobileBrowser.usesMobileBrowser.error.conflict"><![CDATA[You cannot simultaneously select “Uses mobile device” and “Uses desktop”.]]></item>
                <item name="wcf.user.condition.mobileBrowser.usesNoMobileBrowser"><![CDATA[Uses desktop]]></item>
+               <item name="wcf.user.condition.multifactor"><![CDATA[Multi-Factor Authentication]]></item>
+               <item name="wcf.user.condition.multifactor.usesMultifactor"><![CDATA[Uses a Multi-Factor Authentication]]></item>
+               <item name="wcf.user.condition.multifactor.usesMultifactor.error.conflict"><![CDATA[You cannot simultaneously select “Uses a Multi-Factor Authentication” and “Uses no Multi-Factor Authentication”.]]></item>
+               <item name="wcf.user.condition.multifactor.usesNoMultifactor"><![CDATA[Uses no Multi-Factor Authentication]]></item>
                <item name="wcf.user.condition.notGroupIDs"><![CDATA[User Not in User Group(s)]]></item>
                <item name="wcf.user.condition.notGroupIDs.description"><![CDATA[User is not a member of the selected user group(s).]]></item>
                <item name="wcf.user.condition.notGroupIDs.error.groupIDsIntersection"><![CDATA[The selected user group(s) in “User in User Group(s)” and “User Not in User Group(s)” are conflicting.]]></item>