From 8f7b625b7d23f8cb923ccdb03f4ca8a7dca08dcf Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Fri, 22 May 2020 15:55:40 +0200 Subject: [PATCH] Move register state constants to User object --- wcfsetup/install/files/lib/acp/page/IndexPage.class.php | 5 ++--- wcfsetup/install/files/lib/data/user/User.class.php | 5 +++++ wcfsetup/install/files/lib/data/user/UserAction.class.php | 5 ++--- .../install/files/lib/data/user/UserProfile.class.php | 5 ----- .../files/lib/form/AccountManagementForm.class.php | 5 ++--- .../files/lib/form/RegisterActivationForm.class.php | 6 ++---- wcfsetup/install/files/lib/form/RegisterForm.class.php | 8 ++++---- .../lib/form/RegisterNewActivationCodeForm.class.php | 3 +-- .../system/clipboard/action/UserClipboardAction.class.php | 3 +-- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/page/IndexPage.class.php b/wcfsetup/install/files/lib/acp/page/IndexPage.class.php index 86ae7005c2..176ea6aef8 100755 --- a/wcfsetup/install/files/lib/acp/page/IndexPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/IndexPage.class.php @@ -1,6 +1,6 @@ 0"; diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index ff91f24c7f..d9329523b7 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -105,6 +105,11 @@ final class User extends DatabaseObject implements IRouteController, IUserConten */ protected static $userOptions; + const REGISTER_ACTIVATION_NONE = 0; + const REGISTER_ACTIVATION_USER = 1; + const REGISTER_ACTIVATION_ADMIN = 2; + const REGISTER_ACTIVATION_USER_AND_ADMIN = 3; // self::REGISTER_ACTIVATION_USER + self::REGISTER_ACTIVATION_ADMIN + /** @noinspection PhpMissingParentConstructorInspection */ /** * @inheritDoc diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index e280e51f87..b3fb6346db 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -22,7 +22,6 @@ use wcf\system\language\LanguageFactory; use wcf\system\request\RequestHandler; use wcf\system\user\group\assignment\UserGroupAssignmentHandler; use wcf\system\WCF; -use wcf\util\CryptoUtil; use wcf\util\UserRegistrationUtil; /** @@ -626,7 +625,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio public function confirmEmail() { if (empty($this->objects)) $this->readObjects(); - if (REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_ADMIN) { + if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN) { $action = new UserAction($this->objects, 'update', [ 'data' => [ 'emailConfirmed' => null @@ -1029,7 +1028,7 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio throw new PermissionDeniedException(); } - if (!(REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER)) { + if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) { throw new IllegalLinkException(); } diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index d4c0a9c774..bf2d3e4744 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -111,11 +111,6 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { const ACCESS_FOLLOWING = 2; const ACCESS_NOBODY = 3; - const REGISTER_ACTIVATION_NONE = 0; - const REGISTER_ACTIVATION_USER = 1; - const REGISTER_ACTIVATION_ADMIN = 2; - const REGISTER_ACTIVATION_USER_AND_ADMIN = 3; // self::REGISTER_ACTIVATION_USER + self::REGISTER_ACTIVATION_ADMIN - /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/form/AccountManagementForm.class.php b/wcfsetup/install/files/lib/form/AccountManagementForm.class.php index 5677859d54..9882aa5b0b 100644 --- a/wcfsetup/install/files/lib/form/AccountManagementForm.class.php +++ b/wcfsetup/install/files/lib/form/AccountManagementForm.class.php @@ -3,7 +3,6 @@ namespace wcf\form; use wcf\data\user\User; use wcf\data\user\UserAction; use wcf\data\user\UserList; -use wcf\data\user\UserProfile; use wcf\system\email\mime\MimePartFacade; use wcf\system\email\mime\RecipientAwareTextMimePart; use wcf\system\email\Email; @@ -339,12 +338,12 @@ class AccountManagementForm extends AbstractForm { // email if (WCF::getSession()->getPermission('user.profile.canChangeEmail') && $this->email != WCF::getUser()->email && $this->email != WCF::getUser()->newEmail) { - if (!(REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER) && mb_strtolower($this->email) == mb_strtolower(WCF::getUser()->email)) { + if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER) && mb_strtolower($this->email) == mb_strtolower(WCF::getUser()->email)) { // update email $updateParameters['email'] = $this->email; $success[] = 'wcf.user.changeEmail.success'; } - else if (REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER) { + else if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER) { // get reactivation code $activationCode = UserRegistrationUtil::getActivationCode(); diff --git a/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php b/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php index c96645c3d4..be803ec619 100644 --- a/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterActivationForm.class.php @@ -2,7 +2,6 @@ namespace wcf\form; use wcf\data\user\User; use wcf\data\user\UserAction; -use wcf\data\user\UserProfile; use wcf\system\event\EventHandler; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\NamedUserException; @@ -10,7 +9,6 @@ use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; use wcf\system\request\LinkHandler; use wcf\system\WCF; -use wcf\util\CryptoUtil; use wcf\util\HeaderUtil; use wcf\util\StringUtil; @@ -106,7 +104,7 @@ class RegisterActivationForm extends AbstractForm { $this->saved(); // forward to index page - if (REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_ADMIN && !$this->user->isActivated()) { + if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN && !$this->user->isActivated()) { $redirectText = WCF::getLanguage()->getDynamicVariable('wcf.user.registerActivation.success.awaitAdminActivation'); } else { @@ -133,7 +131,7 @@ class RegisterActivationForm extends AbstractForm { * @inheritDoc */ public function show() { - if (!(REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER)) { + if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) { throw new IllegalLinkException(); } diff --git a/wcfsetup/install/files/lib/form/RegisterForm.class.php b/wcfsetup/install/files/lib/form/RegisterForm.class.php index 19901a2279..ded41b4346 100644 --- a/wcfsetup/install/files/lib/form/RegisterForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterForm.class.php @@ -429,7 +429,7 @@ class RegisterForm extends UserAddForm { // generate activation code $addDefaultGroups = true; - if (!empty($this->blacklistMatches) || (REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER && !$registerVia3rdParty) || REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_ADMIN) { + if (!empty($this->blacklistMatches) || (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER && !$registerVia3rdParty) || REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN) { $activationCode = UserRegistrationUtil::getActivationCode(); $emailConfirmCode = bin2hex(\random_bytes(20)); $this->additionalFields['activationCode'] = $activationCode; @@ -476,12 +476,12 @@ class RegisterForm extends UserAddForm { } // activation management - if (REGISTER_ACTIVATION_METHOD == UserProfile::REGISTER_ACTIVATION_NONE && empty($this->blacklistMatches)) { + if (REGISTER_ACTIVATION_METHOD == User::REGISTER_ACTIVATION_NONE && empty($this->blacklistMatches)) { $this->message = 'wcf.user.register.success'; UserGroupAssignmentHandler::getInstance()->checkUsers([$user->userID]); } - else if (REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER && empty($this->blacklistMatches)) { + else if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER && empty($this->blacklistMatches)) { // registering via 3rdParty leads to instant activation if ($registerVia3rdParty) { $this->message = 'wcf.user.register.success'; @@ -498,7 +498,7 @@ class RegisterForm extends UserAddForm { $this->message = 'wcf.user.register.success.needActivation'; } } - else if (REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_ADMIN || !empty($this->blacklistMatches)) { + else if (REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_ADMIN || !empty($this->blacklistMatches)) { $this->message = 'wcf.user.register.success.awaitActivation'; } diff --git a/wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php b/wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php index f6ea6db588..84dd0affe7 100644 --- a/wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterNewActivationCodeForm.class.php @@ -2,7 +2,6 @@ namespace wcf\form; use wcf\data\user\User; use wcf\data\user\UserAction; -use wcf\data\user\UserProfile; use wcf\system\email\mime\MimePartFacade; use wcf\system\email\mime\RecipientAwareTextMimePart; use wcf\system\email\Email; @@ -199,7 +198,7 @@ class RegisterNewActivationCodeForm extends AbstractForm { * @inheritDoc */ public function show() { - if (!(REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER)) { + if (!(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) { throw new IllegalLinkException(); } 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 ceba0e4266..d5d2920f12 100644 --- a/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/action/UserClipboardAction.class.php @@ -4,7 +4,6 @@ use wcf\data\clipboard\action\ClipboardAction; use wcf\data\user\group\UserGroup; use wcf\data\user\User; use wcf\data\user\UserAction; -use wcf\data\user\UserProfile; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\request\LinkHandler; use wcf\system\WCF; @@ -229,7 +228,7 @@ class UserClipboardAction extends AbstractClipboardAction { */ protected function validateResendActivationMail() { // check permissions - if (!WCF::getSession()->getPermission('admin.user.canEnableUser') || !(REGISTER_ACTIVATION_METHOD & UserProfile::REGISTER_ACTIVATION_USER)) { + if (!WCF::getSession()->getPermission('admin.user.canEnableUser') || !(REGISTER_ACTIVATION_METHOD & User::REGISTER_ACTIVATION_USER)) { return []; } -- 2.20.1