Add methods to check the user activation state in user objects
authorjoshuaruesweg <ruesweg@woltlab.com>
Fri, 5 Jun 2020 13:55:17 +0000 (15:55 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Fri, 5 Jun 2020 13:55:17 +0000 (15:55 +0200)
13 files changed:
com.woltlab.wcf/templates/user.tpl
com.woltlab.wcf/templates/userNotice.tpl
wcfsetup/install/files/lib/data/user/User.class.php
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/files/lib/data/user/UserProfile.class.php
wcfsetup/install/files/lib/data/user/UserProfileAction.class.php
wcfsetup/install/files/lib/form/RegisterActivationForm.class.php
wcfsetup/install/files/lib/page/PaidSubscriptionListPage.class.php
wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php
wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php
wcfsetup/install/files/lib/system/importer/UserImporter.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 27ed67a3632bb987fdb252720184d732d59faaa2..b750565ece5aa1dbe86e0d37408e7330a2b8c473 100644 (file)
                                                                        {if $__wcf->session->getPermission('admin.user.canDisableAvatar')}<li><a href="#" class="jsButtonUserDisableAvatar">{lang}wcf.user.{if $user->disableAvatar}enable{else}disable{/if}Avatar{/lang}</a></li>{/if}
                                                                        {if $__wcf->session->getPermission('admin.user.canDisableSignature')}<li><a href="#" class="jsButtonUserDisableSignature">{lang}wcf.user.{if $user->disableSignature}enable{else}disable{/if}Signature{/lang}</a></li>{/if}
                                                                        {if MODULE_USER_COVER_PHOTO && $__wcf->session->getPermission('admin.user.canDisableCoverPhoto')}<li><a href="#" class="jsButtonUserDisableCoverPhoto">{lang}wcf.user.{if $user->disableCoverPhoto}enable{else}disable{/if}CoverPhoto{/lang}</a></li>{/if}
-                                                                       {if $__wcf->session->getPermission('admin.user.canEnableUser')}<li><a href="#" class="jsButtonUserEnable">{lang}wcf.acp.user.{if $user->isActivated()}enable{else}disable{/if}{/lang}</a></li>{/if}
+                                                                       {if $__wcf->session->getPermission('admin.user.canEnableUser')}<li><a href="#" class="jsButtonUserEnable">{lang}wcf.acp.user.{if $user->pendingActivation()}disable{else}enable{/if}{/lang}</a></li>{/if}
                                                                        
                                                                        {if $__wcf->session->getPermission('admin.general.canUseAcp') && $__wcf->session->getPermission('admin.user.canEditUser')}<li><a href="{link controller='UserEdit' object=$user isACP=true}{/link}" class="jsUserInlineEditor">{lang}wcf.user.edit{/lang}</a></li>{/if}
                                                                {/if}
index b3540f9664ba3eab12a4585a8a6880180bc860e2..a30c4ecd5fe48fce75a4ca3330dad7ff005502c3 100644 (file)
                <p class="info" role="status">{lang}wcf.page.availableUpdates{/lang}</p>
        {/if}
        
-       {* user needs email confirmation to be activated *}
-       {if !$__wcf->user->isEmailConfirmed() && !$__wcf->user->isActivated() && REGISTER_ACTIVATION_METHOD & 1 && $templateName != 'registerActivation' && $templateName != 'register' && $templateName != 'redirect' && $__wcf->user->getBlacklistMatches()|empty}
-               <p class="warning" role="status">{lang}wcf.user.register.needActivation{/lang}</p>
-       {/if}
-       
-       {* user needs admin activation *}
-       {if $__wcf->user->isEmailConfirmed() && REGISTER_ACTIVATION_METHOD & 2 && !$__wcf->user->isActivated() && $templateName != 'registerActivation' && $templateName != 'register' && $templateName != 'redirect' && $__wcf->user->getBlacklistMatches()|empty}
-               <p class="warning" role="status">{lang}wcf.user.register.needAdminActivation{/lang}</p>
-       {/if}
-       
-       {* user needs email activation w/o being disabled *}
-       {if !$__wcf->user->isEmailConfirmed() && REGISTER_ACTIVATION_METHOD & 1 && $__wcf->user->isActivated() && $templateName != 'registerActivation' && $templateName != 'register' && $templateName != 'redirect' && $__wcf->user->getBlacklistMatches()|empty}
-               <p class="warning" role="status">{lang}wcf.user.register.needEmailConfirmation{/lang}</p>
+       {if $templateName != 'registerActivation' && $templateName != 'register' && $templateName != 'redirect' && $__wcf->user->getBlacklistMatches()|empty}
+               {if $__wcf->user->requiresEmailActivation()}
+                       <p class="warning" role="status">{lang}wcf.user.register.needActivation{/lang}</p>
+               {elseif $__wcf->user->requiresAdminActivation()}
+                       <p class="warning" role="status">{lang}wcf.user.register.needAdminActivation{/lang}</p>
+               {elseif !$__wcf->user->isEmailConfirmed()}
+                       <p class="warning" role="status">{lang}wcf.user.register.needEmailConfirmation{/lang}</p>
+               {/if}
        {/if}
        
        {hascontent}
index 8cbe1a7818016c007903d591f0e1fd5320eb487f..9bbc5284d172cabc9e7e35efebfb1eef59029d5e 100644 (file)
@@ -410,16 +410,6 @@ final class User extends DatabaseObject implements IRouteController, IUserConten
                return 0;
        }
        
-       /**
-        * Returns true if this user is activated.
-        *
-        * @return      boolean
-        * @since       5.3
-        */
-       public function isActivated() {
-               return $this->activationCode == 0;
-       }
-       
        /**
         * Returns true if the email is confirmed.
         *
@@ -619,7 +609,7 @@ final class User extends DatabaseObject implements IRouteController, IUserConten
         * @return      boolean
         */
        public function canPurchasePaidSubscriptions() {
-               return WCF::getUser()->userID && $this->isActivated();
+               return WCF::getUser()->userID && !$this->pendingActivation();
        }
        
        /**
@@ -630,7 +620,7 @@ final class User extends DatabaseObject implements IRouteController, IUserConten
         * @since 5.2
         */
        public function getBlacklistMatches() {
-               if ($this->isActivated() && $this->blacklistMatches) {
+               if ($this->pendingActivation() && $this->blacklistMatches) {
                        $matches = JSON::decode($this->blacklistMatches);
                        if (is_array($matches)) {
                                return $matches;
@@ -654,4 +644,44 @@ final class User extends DatabaseObject implements IRouteController, IUserConten
                        return WCF::getLanguage()->get('wcf.user.' . $field);
                }, $this->getBlacklistMatches());
        }
+       
+       /**
+        * Returns true if this user is not activated.
+        *
+        * @return      boolean
+        * @since       5.3
+        */
+       public function pendingActivation() {
+               return $this->activationCode != 0;
+       }
+       
+       /**
+        * Returns true if this user requires activation by the user.
+        *
+        * @return      boolean
+        * @since       5.3
+        */
+       public function requiresEmailActivation() {
+               return REGISTER_ACTIVATION_METHOD & self::REGISTER_ACTIVATION_USER && $this->pendingActivation() && !$this->isEmailConfirmed();
+       }
+       
+       /**
+        * Returns true if this user requires the activation by an admin.
+        *
+        * @return      boolean
+        * @since       5.3
+        */
+       public function requiresAdminActivation() {
+               return REGISTER_ACTIVATION_METHOD & self::REGISTER_ACTIVATION_ADMIN && $this->pendingActivation();
+       }
+       
+       /**
+        * Returns true if this user can confirm the email themself.
+        *
+        * @return      boolean
+        * @since       5.3
+        */
+       public function canEmailConfirm() {
+               return REGISTER_ACTIVATION_METHOD & self::REGISTER_ACTIVATION_USER && !$this->isEmailConfirmed();
+       }
 }
index 4495be499b88986d64703460ccc1addd69268c8b..fdca5cf1b0e94ae10f60aba1607558630ab517d2 100644 (file)
@@ -1067,7 +1067,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
                
                foreach ($this->objects as $object) {
                        /** @var UserEditor $object */
-                       if ($object->isActivated()) {
+                       if (!$object->requiresEmailActivation()) {
                                throw new UserInputException('objectIDs');
                        }
                }
index bf2d3e47444aa9b07e208834f68461f5f17cd12b..4e1bffa7d89c191d9c19f36071a60e21f7d3a048 100644 (file)
@@ -881,7 +881,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject {
         * @return      boolean
         */
        public function canEditOwnProfile() {
-               if (!$this->isActivated() || !$this->getPermission('user.profile.canEditUserProfile')) {
+               if ($this->pendingActivation() || !$this->getPermission('user.profile.canEditUserProfile')) {
                        return false;
                }
                
index 4cc50a943f3f59f3a2ef08e03ef7ca3dab3487ec..0eeddbff10d61d9bf5d415f31a6dfa73c654890d 100644 (file)
@@ -407,7 +407,7 @@ class UserProfileAction extends UserAction {
                                $fixUserGroupIDs[$user->userID] = [UserGroup::EVERYONE];
                                $groupIDs[] = UserGroup::EVERYONE;
                        }
-                       if (!$user->isActivated()) {
+                       if ($user->pendingActivation()) {
                                if (!in_array(UserGroup::GUESTS, $groupIDs)) {
                                        if (!isset($fixUserGroupIDs[$user->userID])) $fixUserGroupIDs[$user->userID] = [];
                                        $fixUserGroupIDs[$user->userID][] = UserGroup::GUESTS;
index 1e301270c6e4a88078b1814fb6c48598713e7a5d..e01d196f3b5c37d9245deb51c58c6a3f4a720044 100644 (file)
@@ -104,7 +104,7 @@ class RegisterActivationForm extends AbstractForm {
                $this->saved();
                
                // forward to index page
-               if ((REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN) && !$this->user->isActivated()) {
+               if ($this->user->requiresAdminActivation()) {
                        $redirectText = WCF::getLanguage()->getDynamicVariable('wcf.user.registerActivation.success.awaitAdminActivation');
                }
                else {
index d5c7cf00ed47b3ab4a59cfe9405c1ba436786ee5..714744357dcf807ed9b59509800545d480a62f77 100644 (file)
@@ -43,7 +43,7 @@ class PaidSubscriptionListPage extends AbstractPage {
        public function checkPermissions() {
                parent::checkPermissions();
                
-               if (!WCF::getUser()->isActivated()) {
+               if (WCF::getUser()->pendingActivation()) {
                        throw new PermissionDeniedException();
                }
        }
index 4436a3e7bc63e6ee1e0a36c038bce678e8ad54a6..a699708306c311273d5c7f126c9b9e8b96bd24f6 100644 (file)
@@ -238,7 +238,7 @@ class UserClipboardAction extends AbstractClipboardAction {
                $userIDs = [];
                foreach ($this->objects as $user) {
                        /** @var User $user */
-                       if (!$user->isActivated()) $userIDs[] = $user->userID;
+                       if ($user->pendingActivation()) $userIDs[] = $user->userID;
                }
                
                return $userIDs;
@@ -276,7 +276,8 @@ class UserClipboardAction extends AbstractClipboardAction {
                
                $userIDs = [];
                foreach ($this->objects as $user) {
-                       if (!$user->isActivated()) $userIDs[] = $user->userID;
+                       /** @var User $user */
+                       if ($user->requiresEmailActivation()) $userIDs[] = $user->userID;
                }
                
                return $userIDs;
index 98dd6d5b4437f9410ebb999c264c3f0bfd19bd8d..327044dba1e7c7657db8d1290bacbdba81d7442c 100644 (file)
@@ -104,10 +104,10 @@ class UserStateCondition extends AbstractSingleFieldCondition implements IConten
                /** @noinspection PhpUndefinedFieldInspection */
                $userIsEnabled = $condition->userIsEnabled;
                if ($userIsEnabled !== null) {
-                       if ($userIsEnabled && !$user->isActivated()) {
+                       if ($userIsEnabled && $user->pendingActivation()) {
                                return false;
                        }
-                       else if (!$userIsEnabled && $user->isActivated()) {
+                       else if (!$userIsEnabled && !$user->pendingActivation()) {
                                return false;
                        }
                }
index e0116833f816e099e45626eb870f7abb2ffc102b..a423d5d26a719c4c20494c28aa81e461a832efc3 100644 (file)
@@ -176,7 +176,7 @@ class UserImporter extends AbstractImporter {
                        }
                }
                
-               if ($user->isActivated()) $defaultGroupIDs = UserGroup::getGroupIDsByType([UserGroup::EVERYONE, UserGroup::USERS]);
+               if (!$user->pendingActivation()) $defaultGroupIDs = UserGroup::getGroupIDsByType([UserGroup::EVERYONE, UserGroup::USERS]);
                else $defaultGroupIDs = UserGroup::getGroupIDsByType([UserGroup::EVERYONE, UserGroup::GUESTS]);
                
                $groupIDs = array_merge($groupIDs, $defaultGroupIDs);
index be8d56c679626f69a9d8c03e658b906b2311c50a..d3ce64429bc8551796af0af5713478cff5cd02e1 100644 (file)
@@ -4740,7 +4740,7 @@ Sie sich{/if} bitte an den Administrator unter: {@MAIL_ADMIN_ADDRESS}. Wenn {if
 dich{else}Sie
 sich{/if} nicht bei uns registriert {if LANGUAGE_USE_INFORMAL_VARIANT}hast{else}haben{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese E-Mail ignorieren.]]></item>
                <item name="wcf.user.register.needAdminActivation"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Dein{else}Ihr{/if} Benutzerkonto muss noch von einem Administrator freigeschaltet werden, um den vollen Funktionsumfang dieser Seite nutzen zu können.]]></item>
-               <item name="wcf.user.register.needEmailConfirmation"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} E-Mail-Adresse muss noch bestätigt werden. <a href="{link controller='RegisterActivation'}{/link}">{if LANGUAGE_USE_INFORMAL_VARIANT}Bestätige jetzt deine{else}Bestätigen Sie jetzt Ihre{/if} E-Mail-Adresse</a>.]]></item>
+               <item name="wcf.user.register.needEmailConfirmation"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} E-Mail-Adresse muss bestätigt werden. {if $__wcf->user->canEmailConfirm()}<a href="{link controller='RegisterActivation'}{/link}">{if LANGUAGE_USE_INFORMAL_VARIANT}Bestätige jetzt deine{else}Bestätigen Sie jetzt Ihre{/if} E-Mail-Adresse</a>{else}Wenden Sie sich dafür direkt an den Administrator dieser Seite{/if}.]]></item>
                <!-- Success Messages -->
                <item name="wcf.user.register.success"><![CDATA[Vielen Dank für die Registrierung, {$user->username}. {if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Registrierung ist hiermit vollständig abgeschlossen.]]></item>
                <item name="wcf.user.register.success.needActivation"><![CDATA[Vielen Dank für die Registrierung, {$user->username}.<br>
index 8f8f2ab5378a94333e5c64274af7aedf205c6017..5159aaaa039eac950b9127f3353fdab86bd33e6a 100644 (file)
@@ -4727,13 +4727,13 @@ confirm the validity of your email address once:
 
     {link controller='RegisterActivation' isEmail=true}u={@$mailbox->getUser()->userID}&a={@$mailbox->getUser()->emailConfirmed}{/link} {* this line ends with a space *}
 
-Your activation code is: {@$mailbox->getUser()->activationCode} {* this line ends with a space *}
+Your activation code is: {@$mailbox->getUser()->emailConfirmed} {* this line ends with a space *}
 
 If you have trouble confirming your email address, please contact the
 administrator at: {@MAIL_ADMIN_ADDRESS}. Please ignore this email if you did
 not register with us.]]></item>
                <item name="wcf.user.register.needAdminActivation"><![CDATA[Your account must be activated by an administrator in order to use the full scope of the website.]]></item>
-               <item name="wcf.user.register.needEmailConfirmation"><![CDATA[Your email address is not activated yet. <a href="{link controller='RegisterActivation'}{/link}">Activate now your email address</a>.]]></item>
+               <item name="wcf.user.register.needEmailConfirmation"><![CDATA[Your email address is not activated yet. <a href="{link controller='RegisterActivation'}{/link}">Activate now your email address</a>. {if $__wcf->user->canEmailConfirm()}<a href="{link controller='RegisterActivation'}{/link}">Confirm your email address</a>{else}To activate your email address contact the administrator of this site.{/if}.]]></item>
                <!-- Success Messages -->
                <item name="wcf.user.register.success"><![CDATA[Thank you for registering, {$user->username}.<br>
 Your registration is now completed.]]></item>