Add condition for user with(out) confirmed email addresses
authorjoshuaruesweg <ruesweg@woltlab.com>
Sat, 23 May 2020 18:01:07 +0000 (20:01 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sat, 23 May 2020 18:01:07 +0000 (20:01 +0200)
wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 013409ff56c3f6508c194cae162d8da90bd5b1d8..b2336559a383a2379445fc1b8576b3e272d62c8b 100644 (file)
@@ -47,6 +47,19 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten
         */
        protected $userIsNotBanned = 0;
        
+       /**
+        * true if the the user is be email confirmed
+        *
+        * @var integer
+        */
+       protected $userIsEmailConfirmed = 0;
+       
+       /**
+        * true if the the user is not be email confirmed
+        * @var integer
+        */
+       protected $userIsNotEmailConfirmed = 0;
+       
        /**
         * @inheritDoc
         */
@@ -67,6 +80,15 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten
                                $objectList->getConditionBuilder()->add('user_table.activationCode <> ?', [0]);
                        }
                }
+               
+               if (isset($conditionData['userIsEmailConfirmed'])) {
+                       if ($conditionData['userIsEmailConfirmed']) {
+                               $objectList->getConditionBuilder()->add('user_table.emailConfirmed IS NULL');
+                       }
+                       else {
+                               $objectList->getConditionBuilder()->add('user_table.emailConfirmed IS NOT NULL');
+                       }
+               }
        }
        
        /**
@@ -90,6 +112,17 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten
                        }
                }
                
+               /** @noinspection PhpUndefinedFieldInspection */
+               $userIsEmailConfirmed = $condition->userIsEmailConfirmed;
+               if ($userIsEmailConfirmed !== null) {
+                       if ($userIsEmailConfirmed && !$user->isEmailConfirmed()) {
+                               return false;
+                       }
+                       else if (!$userIsEmailConfirmed && $user->isEmailConfirmed()) {
+                               return false;
+                       }
+               }
+               
                return true;
        }
        
@@ -111,6 +144,12 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten
                else if ($this->userIsDisabled) {
                        $data['userIsEnabled'] = 0;
                }
+               if ($this->userIsEmailConfirmed) {
+                       $data['userIsEmailConfirmed'] = 1;
+               }
+               else if ($this->userIsNotEmailConfirmed) {
+                       $data['userIsEmailConfirmed'] = 0;
+               } 
                
                if (!empty($data)) {
                        return $data;
@@ -142,12 +181,16 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten
                $userIsBanned = WCF::getLanguage()->get('wcf.user.condition.state.isBanned');
                $userIsDisabled = WCF::getLanguage()->get('wcf.user.condition.state.isDisabled');
                $userIsEnabled = WCF::getLanguage()->get('wcf.user.condition.state.isEnabled');
+               $userIsEmailConfirmed = WCF::getLanguage()->get('wcf.user.condition.state.isEmailConfirmed');
+               $userIsNotEmailConfirmed = WCF::getLanguage()->get('wcf.user.condition.state.isNotEmailConfirmed');
                
                return <<<HTML
 <label><input type="checkbox" name="userIsBanned" value="1"{$this->getCheckedAttribute('userIsBanned')}> {$userIsBanned}</label>
 <label><input type="checkbox" name="userIsNotBanned" value="1"{$this->getCheckedAttribute('userIsNotBanned')}> {$userIsNotBanned}</label>
 <label><input type="checkbox" name="userIsEnabled" value="1"{$this->getCheckedAttribute('userIsEnabled')}> {$userIsEnabled}</label>
 <label><input type="checkbox" name="userIsDisabled" value="1"{$this->getCheckedAttribute('userIsDisabled')}> {$userIsDisabled}</label>
+<label><input type="checkbox" name="userIsEmailConfirmed" value="1"{$this->getCheckedAttribute('userIsEmailConfirmed')}> {$userIsEmailConfirmed}</label>
+<label><input type="checkbox" name="userIsNotEmailConfirmed" value="1"{$this->getCheckedAttribute('userIsNotEmailConfirmed')}> {$userIsNotEmailConfirmed}</label>
 HTML;
        }
        
@@ -159,6 +202,8 @@ HTML;
                if (isset($_POST['userIsDisabled'])) $this->userIsDisabled = 1;
                if (isset($_POST['userIsEnabled'])) $this->userIsEnabled = 1;
                if (isset($_POST['userIsNotBanned'])) $this->userIsNotBanned = 1;
+               if (isset($_POST['userIsEmailConfirmed'])) $this->userIsEmailConfirmed = 1;
+               if (isset($_POST['userIsNotEmailConfirmed'])) $this->userIsNotEmailConfirmed = 1;
        }
        
        /**
@@ -169,6 +214,8 @@ HTML;
                $this->userIsDisabled = 0;
                $this->userIsEnabled = 0;
                $this->userIsNotBanned = 0;
+               $this->userIsEmailConfirmed = 0;
+               $this->userIsNotEmailConfirmed = 0;
        }
        
        /**
@@ -188,6 +235,13 @@ HTML;
                        $this->userIsEnabled = $userIsEnabled;
                        $this->userIsDisabled = !$userIsEnabled;
                }
+               
+               /** @noinspection PhpUndefinedFieldInspection */
+               $userIsEmailConfirmed = $condition->userIsEmailConfirmed;
+               if ($condition->userIsEmailConfirmed !== null) {
+                       $this->userIsEmailConfirmed = $userIsEmailConfirmed;
+                       $this->userIsNotEmailConfirmed = !$userIsEmailConfirmed;
+               }
        }
        
        /**
@@ -205,6 +259,12 @@ HTML;
                        
                        throw new UserInputException('userIsEnabled', 'conflict');
                }
+               
+               if ($this->userIsEmailConfirmed && $this->userIsNotEmailConfirmed) {
+                       $this->errorMessage = 'wcf.user.condition.state.isEmailConfirmed.error.conflict';
+                       
+                       throw new UserInputException('userIsEmailConfirmed', 'conflict');
+               }
        }
        
        /**
index 91e580143ebca0a63be2698f1c7bf0ddd3f72edc..0d67613385bce8f94bdaa01b88891a0ee3fe64a0 100644 (file)
@@ -4958,6 +4958,9 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
                <item name="wcf.user.condition.state.isEnabled"><![CDATA[Aktiviert]]></item>
                <item name="wcf.user.condition.state.isEnabled.error.conflict"><![CDATA[„Aktiviert“ und „Nicht aktiviert“ können nicht gleichzeitig ausgewählt werden.]]></item>
                <item name="wcf.user.condition.state.isNotBanned"><![CDATA[Nicht gesperrt]]></item>
+               <item name="wcf.user.condition.state.isEmailConfirmed"><![CDATA[Hat eine bestätigte E-Mail-Adresse]]></item>
+               <item name="wcf.user.condition.state.isEmailConfirmed.error.conflict"><![CDATA[„Hat eine bestätigte E-Mail-Adresse“ und „Hat keine bestätigte E-Mail-Adresse“ können nicht gleichzeitig ausgewählt werden.]]></item>
+               <item name="wcf.user.condition.state.isNotEmailConfirmed"><![CDATA[Hat keine bestätigte E-Mail-Adresse]]></item>
                <item name="wcf.user.condition.userTrophyIDs"><![CDATA[hat Trophäe]]></item>
                <item name="wcf.user.condition.userTrophyIDs.description"><![CDATA[Benutzer müssen alle ausgewählten Trophäen mindestens einmal erhalten haben.]]></item>
                <item name="wcf.user.condition.notUserTrophyIDs"><![CDATA[hat nicht Trophäe]]></item>
index b61535a7cafe3df1c8e0a142e185ac31d8305057..99924780843282bd09d571f8cfe29733b58d8b2b 100644 (file)
@@ -4953,6 +4953,9 @@ Open the link below to access the user profile:
                <item name="wcf.user.condition.state.isEnabled"><![CDATA[Approved]]></item>
                <item name="wcf.user.condition.state.isEnabled.error.conflict"><![CDATA[You cannot simultaneously select “Approved” and “Awaiting Approval”.]]></item>
                <item name="wcf.user.condition.state.isNotBanned"><![CDATA[Not Banned]]></item>
+               <item name="wcf.user.condition.state.isEmailConfirmed"><![CDATA[Has a confirmed email address]]></item>
+               <item name="wcf.user.condition.state.isEmailConfirmed.error.conflict"><![CDATA[You cannot simultaneously select “Has a confirmed email address” and “Has not a confirmed email address”.]]></item>
+               <item name="wcf.user.condition.state.isNotEmailConfirmed"><![CDATA[Has not a confirmed email address]]></item>
                <item name="wcf.user.condition.userTrophyIDs"><![CDATA[User has Trophy]]></item>
                <item name="wcf.user.condition.userTrophyIDs.description"><![CDATA[User has received the selected trophies.]]></item>
                <item name="wcf.user.condition.notUserTrophyIDs"><![CDATA[User does not have Trophy]]></item>