From c5fd92361163a6279245e3615f9e737ff6bd22f3 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Fri, 5 Jun 2020 15:55:17 +0200 Subject: [PATCH] Add methods to check the user activation state in user objects --- com.woltlab.wcf/templates/user.tpl | 2 +- com.woltlab.wcf/templates/userNotice.tpl | 21 +++----- .../files/lib/data/user/User.class.php | 54 ++++++++++++++----- .../files/lib/data/user/UserAction.class.php | 2 +- .../files/lib/data/user/UserProfile.class.php | 2 +- .../lib/data/user/UserProfileAction.class.php | 2 +- .../lib/form/RegisterActivationForm.class.php | 2 +- .../page/PaidSubscriptionListPage.class.php | 2 +- .../action/UserClipboardAction.class.php | 5 +- .../condition/UserStateCondition.class.php | 4 +- .../system/importer/UserImporter.class.php | 2 +- wcfsetup/install/lang/de.xml | 2 +- wcfsetup/install/lang/en.xml | 4 +- 13 files changed, 65 insertions(+), 39 deletions(-) diff --git a/com.woltlab.wcf/templates/user.tpl b/com.woltlab.wcf/templates/user.tpl index 27ed67a363..b750565ece 100644 --- a/com.woltlab.wcf/templates/user.tpl +++ b/com.woltlab.wcf/templates/user.tpl @@ -307,7 +307,7 @@ {if $__wcf->session->getPermission('admin.user.canDisableAvatar')}
  • {lang}wcf.user.{if $user->disableAvatar}enable{else}disable{/if}Avatar{/lang}
  • {/if} {if $__wcf->session->getPermission('admin.user.canDisableSignature')}
  • {lang}wcf.user.{if $user->disableSignature}enable{else}disable{/if}Signature{/lang}
  • {/if} {if MODULE_USER_COVER_PHOTO && $__wcf->session->getPermission('admin.user.canDisableCoverPhoto')}
  • {lang}wcf.user.{if $user->disableCoverPhoto}enable{else}disable{/if}CoverPhoto{/lang}
  • {/if} - {if $__wcf->session->getPermission('admin.user.canEnableUser')}
  • {lang}wcf.acp.user.{if $user->isActivated()}enable{else}disable{/if}{/lang}
  • {/if} + {if $__wcf->session->getPermission('admin.user.canEnableUser')}
  • {lang}wcf.acp.user.{if $user->pendingActivation()}disable{else}enable{/if}{/lang}
  • {/if} {if $__wcf->session->getPermission('admin.general.canUseAcp') && $__wcf->session->getPermission('admin.user.canEditUser')}
  • {lang}wcf.user.edit{/lang}
  • {/if} {/if} diff --git a/com.woltlab.wcf/templates/userNotice.tpl b/com.woltlab.wcf/templates/userNotice.tpl index b3540f9664..a30c4ecd5f 100644 --- a/com.woltlab.wcf/templates/userNotice.tpl +++ b/com.woltlab.wcf/templates/userNotice.tpl @@ -10,19 +10,14 @@

    {lang}wcf.page.availableUpdates{/lang}

    {/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} -

    {lang}wcf.user.register.needActivation{/lang}

    - {/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} -

    {lang}wcf.user.register.needAdminActivation{/lang}

    - {/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} -

    {lang}wcf.user.register.needEmailConfirmation{/lang}

    + {if $templateName != 'registerActivation' && $templateName != 'register' && $templateName != 'redirect' && $__wcf->user->getBlacklistMatches()|empty} + {if $__wcf->user->requiresEmailActivation()} +

    {lang}wcf.user.register.needActivation{/lang}

    + {elseif $__wcf->user->requiresAdminActivation()} +

    {lang}wcf.user.register.needAdminActivation{/lang}

    + {elseif !$__wcf->user->isEmailConfirmed()} +

    {lang}wcf.user.register.needEmailConfirmation{/lang}

    + {/if} {/if} {hascontent} diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index 8cbe1a7818..9bbc5284d1 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -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(); + } } diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index 4495be499b..fdca5cf1b0 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -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'); } } diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index bf2d3e4744..4e1bffa7d8 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -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; } diff --git a/wcfsetup/install/files/lib/data/user/UserProfileAction.class.php b/wcfsetup/install/files/lib/data/user/UserProfileAction.class.php index 4cc50a943f..0eeddbff10 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfileAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfileAction.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php b/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php index 1e301270c6..e01d196f3b 100644 --- a/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php @@ -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 { diff --git a/wcfsetup/install/files/lib/page/PaidSubscriptionListPage.class.php b/wcfsetup/install/files/lib/page/PaidSubscriptionListPage.class.php index d5c7cf00ed..714744357d 100644 --- a/wcfsetup/install/files/lib/page/PaidSubscriptionListPage.class.php +++ b/wcfsetup/install/files/lib/page/PaidSubscriptionListPage.class.php @@ -43,7 +43,7 @@ class PaidSubscriptionListPage extends AbstractPage { public function checkPermissions() { parent::checkPermissions(); - if (!WCF::getUser()->isActivated()) { + if (WCF::getUser()->pendingActivation()) { throw new PermissionDeniedException(); } } diff --git a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php index 4436a3e7bc..a699708306 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php index 98dd6d5b44..327044dba1 100644 --- a/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserStateCondition.class.php @@ -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; } } diff --git a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php index e0116833f8..a423d5d26a 100644 --- a/wcfsetup/install/files/lib/system/importer/UserImporter.class.php +++ b/wcfsetup/install/files/lib/system/importer/UserImporter.class.php @@ -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); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index be8d56c679..d3ce64429b 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -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.]]> - {if LANGUAGE_USE_INFORMAL_VARIANT}Bestätige jetzt deine{else}Bestätigen Sie jetzt Ihre{/if} E-Mail-Adresse.]]> + user->canEmailConfirm()}{if LANGUAGE_USE_INFORMAL_VARIANT}Bestätige jetzt deine{else}Bestätigen Sie jetzt Ihre{/if} E-Mail-Adresse{else}Wenden Sie sich dafür direkt an den Administrator dieser Seite{/if}.]]> username}. {if LANGUAGE_USE_INFORMAL_VARIANT}Deine{else}Ihre{/if} Registrierung ist hiermit vollständig abgeschlossen.]]> username}.
    diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 8f8f2ab537..5159aaaa03 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -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.]]>
    - Activate now your email address.]]> + Activate now your email address. {if $__wcf->user->canEmailConfirm()}Confirm your email address{else}To activate your email address contact the administrator of this site.{/if}.]]> username}.
    Your registration is now completed.]]>
    -- 2.20.1