From d82b05e5ea6d2139fb966d2c41025bc1db79195c Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 18 Jan 2019 17:20:08 +0100 Subject: [PATCH] Added notification for new user registrations Closes #2803 --- com.woltlab.wcf/objectType.xml | 6 ++ .../email_notification_userRegistration.tpl | 23 +++++ com.woltlab.wcf/userNotificationEvent.xml | 8 ++ .../files/lib/form/RegisterForm.class.php | 46 ++++++++++ ...egistrationUserNotificationEvent.class.php | 89 +++++++++++++++++++ ...gistrationUserNotificationObject.class.php | 44 +++++++++ ...rationUserNotificationObjectType.class.php | 31 +++++++ wcfsetup/install/lang/de.xml | 8 ++ wcfsetup/install/lang/en.xml | 8 ++ 9 files changed, 263 insertions(+) create mode 100644 com.woltlab.wcf/templates/email_notification_userRegistration.tpl create mode 100644 wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php create mode 100644 wcfsetup/install/files/lib/system/user/notification/object/UserRegistrationUserNotificationObject.class.php create mode 100644 wcfsetup/install/files/lib/system/user/notification/object/type/UserRegistrationUserNotificationObjectType.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 4ed5c37ef0..77ac2aaef5 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -174,6 +174,12 @@ wcf\system\user\notification\object\type\UserFollowUserNotificationObjectType com.woltlab.wcf.user + + com.woltlab.wcf.user.registration.notification + com.woltlab.wcf.notification.objectType + wcf\system\user\notification\object\type\UserRegistrationUserNotificationObjectType + com.woltlab.wcf.administration + com.woltlab.wcf.user.recentActivityEvent.follow com.woltlab.wcf.user.recentActivityEvent diff --git a/com.woltlab.wcf/templates/email_notification_userRegistration.tpl b/com.woltlab.wcf/templates/email_notification_userRegistration.tpl new file mode 100644 index 0000000000..fe1a66794a --- /dev/null +++ b/com.woltlab.wcf/templates/email_notification_userRegistration.tpl @@ -0,0 +1,23 @@ +{assign var='count' value=$event->getAuthors()|count}{assign var='guestTimesTriggered' value=$event->getNotification()->guestTimesTriggered}{assign var='authors' value=$event->getAuthors()|array_values} +{if $mimeType === 'text/plain'} + {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.plaintext{/lang}{/capture} + {lang}wcf.user.notification.userRegistration.mail.plaintext{/lang} +{else} + {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.html{/lang}{/capture} + {lang}wcf.user.notification.userRegistration.mail.html{/lang} + {assign var='user' value=$event->getAuthor()} + + {if $notificationType == 'instant'}{assign var='avatarSize' value=48} + {else}{assign var='avatarSize' value=32}{/if} + {capture assign='userContent'} + + + + + +
{@$user->getAvatar()->getImageTag($avatarSize)} + {include file='email_userInformationHeadline'} +
+ {/capture} + {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$userContent sandbox=true} +{/if} diff --git a/com.woltlab.wcf/userNotificationEvent.xml b/com.woltlab.wcf/userNotificationEvent.xml index d504303145..ebc83050d8 100644 --- a/com.woltlab.wcf/userNotificationEvent.xml +++ b/com.woltlab.wcf/userNotificationEvent.xml @@ -114,5 +114,13 @@ wcf\system\user\notification\event\ArticleUserNotificationEvent 1 + + + registration + com.woltlab.wcf.user.registration.notification + wcf\system\user\notification\event\UserRegistrationUserNotificationEvent + admin.user.canSearchUser + 0 + diff --git a/wcfsetup/install/files/lib/form/RegisterForm.class.php b/wcfsetup/install/files/lib/form/RegisterForm.class.php index bbcb425657..1fb701d07a 100644 --- a/wcfsetup/install/files/lib/form/RegisterForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterForm.class.php @@ -23,6 +23,8 @@ use wcf\system\exception\UserInputException; use wcf\system\language\LanguageFactory; use wcf\system\request\LinkHandler; use wcf\system\user\authentication\UserAuthenticationFactory; +use wcf\system\user\notification\object\UserRegistrationUserNotificationObject; +use wcf\system\user\notification\UserNotificationHandler; use wcf\system\WCF; use wcf\util\HeaderUtil; use wcf\util\StringUtil; @@ -487,6 +489,8 @@ class RegisterForm extends UserAddForm { $email->send(); } + $this->fireNotificationEvent($user); + if ($this->captchaObjectType) { $this->captchaObjectType->getProcessor()->reset(); } @@ -505,4 +509,46 @@ class RegisterForm extends UserAddForm { HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->getDynamicVariable($this->message, ['user' => $user]), 15); exit; } + + /** + * @param User $user + * @throws SystemException + * @since 5.2 + */ + protected function fireNotificationEvent(User $user) { + $recipientIDs = $this->getRecipientsForNotificationEvent(); + if (!empty($recipientIDs)) { + UserNotificationHandler::getInstance()->fireEvent( + 'registration', + 'com.woltlab.wcf.user.registration.notification', + new UserRegistrationUserNotificationObject($user), + $recipientIDs + ); + } + } + + /** + * @return integer[] + * @since 5.2 + */ + protected function getRecipientsForNotificationEvent() { + $sql = "SELECT userID + FROM wcf".WCF_N."_user_to_group + WHERE groupID IN ( + SELECT groupID + FROM wcf".WCF_N."_user_group_option_value + WHERE optionID IN ( + SELECT optionID + FROM wcf".WCF_N."_user_group_option + WHERE optionName = ? + ) + AND optionValue = ? + )"; + $statement = WCF::getDB()->prepareStatement($sql, 100); + $statement->execute([ + 'admin.user.canSearchUser', + 1 + ]); + return $statement->fetchAll(\PDO::FETCH_COLUMN); + } } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php new file mode 100644 index 0000000000..7f3482ee74 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php @@ -0,0 +1,89 @@ + + * @package WoltLabSuite\Core\System\User\Notification\Event + * @since 5.2 + * + * @method UserRegistrationUserNotificationObject getUserNotificationObject() + */ +class UserRegistrationUserNotificationEvent extends AbstractUserNotificationEvent implements ITestableUserNotificationEvent { + use TTestableUserNotificationEvent; + + /** + * @inheritDoc + */ + protected $stackable = true; + + /** + * @inheritDoc + */ + public function getTitle() { + $count = count($this->getAuthors()); + if ($count > 1) { + return $this->getLanguage()->getDynamicVariable('wcf.user.notification.userRegistration.title.stacked', ['count' => $count]); + } + + return $this->getLanguage()->get('wcf.user.notification.userRegistration.title'); + } + + /** + * @inheritDoc + */ + public function getMessage() { + $authors = array_values($this->getAuthors()); + $count = count($authors); + + if ($count > 1) { + return $this->getLanguage()->getDynamicVariable('wcf.user.notification.userRegistration.message.stacked', [ + 'author' => $this->author, + 'authors' => $authors, + 'count' => $count, + 'others' => $count - 1 + ]); + } + + return $this->getLanguage()->getDynamicVariable('wcf.user.notification.userRegistration.message', ['author' => $this->author]); + } + + /** + * @inheritDoc + */ + public function getEmailMessage($notificationType = 'instant') { + return [ + 'template' => 'email_notification_userRegistration', + 'application' => 'wcf' + ]; + } + + /** + * @inheritDoc + */ + public function getLink() { + return LinkHandler::getInstance()->getLink('User', ['object' => $this->author]); + } + + /** + * @inheritDoc + */ + public function getEventHash() { + return sha1($this->eventID); + } + + /** + * @inheritDoc + * @return UserFollowUserNotificationObject[] + */ + public static function getTestObjects(UserProfile $recipient, UserProfile $author) { + return [new UserRegistrationUserNotificationObject($author)]; + } +} diff --git a/wcfsetup/install/files/lib/system/user/notification/object/UserRegistrationUserNotificationObject.class.php b/wcfsetup/install/files/lib/system/user/notification/object/UserRegistrationUserNotificationObject.class.php new file mode 100644 index 0000000000..3a9057e174 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/notification/object/UserRegistrationUserNotificationObject.class.php @@ -0,0 +1,44 @@ + + * @package WoltLabSuite\Core\System\User\Notification\Object + * @since 5.2 + * + * @method User getDecoratedObject() + * @mixin User + */ +class UserRegistrationUserNotificationObject extends DatabaseObjectDecorator implements IUserNotificationObject { + /** + * @inheritDoc + */ + protected static $baseClass = User::class; + + /** + * @inheritDoc + */ + public function getTitle() { + return $this->getDecoratedObject()->getTitle(); + } + + /** + * @inheritDoc + */ + public function getURL() { + return $this->getDecoratedObject()->getLink(); + } + + /** + * @inheritDoc + */ + public function getAuthorID() { + return $this->userID; + } +} diff --git a/wcfsetup/install/files/lib/system/user/notification/object/type/UserRegistrationUserNotificationObjectType.class.php b/wcfsetup/install/files/lib/system/user/notification/object/type/UserRegistrationUserNotificationObjectType.class.php new file mode 100644 index 0000000000..82e1983c37 --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/notification/object/type/UserRegistrationUserNotificationObjectType.class.php @@ -0,0 +1,31 @@ + + * @package WoltLabSuite\Core\System\User\Notification\Object\Type + * @since 5.2 + */ +class UserRegistrationUserNotificationObjectType extends AbstractUserNotificationObjectType { + /** + * @inheritDoc + */ + protected static $decoratorClassName = UserRegistrationUserNotificationObject::class; + + /** + * @inheritDoc + */ + protected static $objectClassName = User::class; + + /** + * @inheritDoc + */ + protected static $objectListClassName = UserList::class; +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index cfc4858d8d..a608755c49 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4870,6 +4870,8 @@ Benachrichtigungen auf {PAGE_TITLE|language getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()} erhalten.]]> + + @@ -4924,6 +4926,12 @@ Benachrichtigungen auf {PAGE_TITLE|language + + + getAnchorTag()} hat sich registriert.]]> + getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere Benutzer{/if} haben sich registriert.]]> + + {@$authorList} {if $count == 1}hat{else}haben{/if} sich registriert:

]]>
getUser()->userID}{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} noch keine sichtbaren Informationen hinterlegt.{else}Der Benutzer hat noch keine für {if LANGUAGE_USE_INFORMAL_VARIANT}dich{else}Sie{/if} sichtbaren Informationen hinterlegt.{/if}]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 7d643b1114..99702f7fe3 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4868,6 +4868,8 @@ your notifications on
{PAGE_TITLE|language} getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}.]]> + + @@ -4923,6 +4925,12 @@ your notifications on {PAGE_TITLE|language} + + + getAnchorTag()} has registered.]]> + getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} have registered.]]> + + {@$authorList} {if $count == 1}has{else}have{/if} registered:

]]>
getUser()->userID}You have not provided any details yet.{else}There are not any details visible to you.{/if}]]> -- 2.20.1