Added notification for new user registrations
authorMarcel Werk <burntime@woltlab.com>
Fri, 18 Jan 2019 16:20:08 +0000 (17:20 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 18 Jan 2019 16:20:08 +0000 (17:20 +0100)
Closes #2803

com.woltlab.wcf/objectType.xml
com.woltlab.wcf/templates/email_notification_userRegistration.tpl [new file with mode: 0644]
com.woltlab.wcf/userNotificationEvent.xml
wcfsetup/install/files/lib/form/RegisterForm.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserRegistrationUserNotificationEvent.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/notification/object/UserRegistrationUserNotificationObject.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/user/notification/object/type/UserRegistrationUserNotificationObjectType.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 4ed5c37ef06a38ecb11208017e4f588045580c7b..77ac2aaef5f2dd1b75862a3ff1a182f12844f2a5 100644 (file)
                        <classname>wcf\system\user\notification\object\type\UserFollowUserNotificationObjectType</classname>
                        <category>com.woltlab.wcf.user</category>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.user.registration.notification</name>
+                       <definitionname>com.woltlab.wcf.notification.objectType</definitionname>
+                       <classname>wcf\system\user\notification\object\type\UserRegistrationUserNotificationObjectType</classname>
+                       <category>com.woltlab.wcf.administration</category>
+               </type>
                <type>
                        <name>com.woltlab.wcf.user.recentActivityEvent.follow</name>
                        <definitionname>com.woltlab.wcf.user.recentActivityEvent</definitionname>
diff --git a/com.woltlab.wcf/templates/email_notification_userRegistration.tpl b/com.woltlab.wcf/templates/email_notification_userRegistration.tpl
new file mode 100644 (file)
index 0000000..fe1a667
--- /dev/null
@@ -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'}
+               <table cellpadding="0" cellspacing="0" border="0">
+                       <tr>
+                               <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$user->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
+                               <td class="boxContent">
+                                       {include file='email_userInformationHeadline'}
+                               </td>
+                       </tr>
+               </table>
+       {/capture}
+       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$userContent sandbox=true}
+{/if}
index d504303145bfeecc14e4494b24c1e54943d3e79a..ebc83050d80c2e7a4a407dddea4d298678db647c 100644 (file)
                        <classname>wcf\system\user\notification\event\ArticleUserNotificationEvent</classname>
                        <preset>1</preset>
                </event>
+               
+               <event>
+                       <name>registration</name>
+                       <objecttype>com.woltlab.wcf.user.registration.notification</objecttype>
+                       <classname>wcf\system\user\notification\event\UserRegistrationUserNotificationEvent</classname>
+                       <permissions>admin.user.canSearchUser</permissions>
+                       <preset>0</preset>
+               </event>
        </import>
 </data>
index bbcb4256571d3d96fbc2dc1caa8ceabac7f6844e..1fb701d07a7661974d93e6fe736ccafc90adb8aa 100644 (file)
@@ -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 (file)
index 0000000..7f3482e
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+namespace wcf\system\user\notification\event;
+use wcf\data\user\UserProfile;
+use wcf\system\request\LinkHandler;
+use wcf\system\user\notification\object\UserFollowUserNotificationObject;
+use wcf\system\user\notification\object\UserRegistrationUserNotificationObject;
+
+/**
+ * Notification event for new user registrations.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..3a9057e
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+namespace wcf\system\user\notification\object;
+use wcf\data\DatabaseObjectDecorator;
+use wcf\data\user\User;
+
+/**
+ * Represents a new user registration as a notification object.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 0000000..82e1983
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+namespace wcf\system\user\notification\object\type;
+use wcf\data\user\User;
+use wcf\data\user\UserList;
+use wcf\system\user\notification\object\UserRegistrationUserNotificationObject;
+
+/**
+ * Represents a new user registration as a notification object type.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+}
index cfc4858d8da63999d4aa84edf2e5b4069f719ef9..a608755c49f9790673563f3f83eb94c447f11af1 100644 (file)
@@ -4870,6 +4870,8 @@ Benachrichtigungen auf <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language
                <item name="wcf.user.notification.com.woltlab.wcf.userTrophy.notification.received"><![CDATA[Trophäe erhalten]]></item>
                <item name="wcf.user.notification.trophy.received.title"><![CDATA[Trophäe erhalten]]></item>
                <item name="wcf.user.notification.trophy.received.message"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} die Trophäe <a href="{$userTrophy->getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}</a> erhalten.]]></item>
+               <item name="wcf.user.notification.com.woltlab.wcf.administration"><![CDATA[Administration]]></item>
+               <item name="wcf.user.notification.com.woltlab.wcf.user.registration.notification.registration"><![CDATA[Neue Registrierung durch Benutzer]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation"><![CDATA[Moderation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation.queue.notification.comment"><![CDATA[Neuer Kommentar in der Moderation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation.queue.response.notification.commentResponse"><![CDATA[Neue Antwort auf einen Kommentar in der Moderation]]></item>
@@ -4924,6 +4926,12 @@ Benachrichtigungen auf <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language
                <item name="wcf.user.notification.com.woltlab.wcf.articleComment.response.notification.commentResponseOwner"><![CDATA[Neue Antwort auf einen Kommentar zu Ihrem Artikel]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.articleComment.response.notification.commentResponse"><![CDATA[Neue Antwort auf einen Kommentar von Ihnen]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.articleComment.notification.comment"><![CDATA[Neuer Kommentar zu Ihrem Artikel]]></item>
+               <item name="wcf.user.notification.userRegistration.title"><![CDATA[Neue Benutzer-Registrierung]]></item>
+               <item name="wcf.user.notification.userRegistration.title.stacked"><![CDATA[{#$count} neue Benutzer-Registrierungen]]></item>
+               <item name="wcf.user.notification.userRegistration.message"><![CDATA[{@$author->getAnchorTag()} hat sich registriert.]]></item>
+               <item name="wcf.user.notification.userRegistration.message.stacked"><![CDATA[{if $count < 4}{@$authors[0]->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.]]></item>
+               <item name="wcf.user.notification.userRegistration.mail.plaintext"><![CDATA[{@$authorList} {if $count == 1}hat{else}haben{/if} sich registriert.]]></item>
+               <item name="wcf.user.notification.userRegistration.mail.html"><![CDATA[<p>{@$authorList} {if $count == 1}hat{else}haben{/if} sich registriert:</p>]]></item>
        </category>
        <category name="wcf.user.profile">
                <item name="wcf.user.profile.content.about.noPublicData"><![CDATA[{if $userID == $__wcf->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}]]></item>
index 7d643b1114aab8fb7ceed03444940ce68fdd8532..99702f7fe3775954d74c1fbe59eaab954370c640 100644 (file)
@@ -4868,6 +4868,8 @@ your notifications on <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language}
                <item name="wcf.user.notification.com.woltlab.wcf.userTrophy.notification.received"><![CDATA[Notify me when I receive a trophy]]></item>
                <item name="wcf.user.notification.trophy.received.title"><![CDATA[Trophy received]]></item>
                <item name="wcf.user.notification.trophy.received.message"><![CDATA[You received the trophy <a href="{$userTrophy->getTrophy()->getLink()}">{$userTrophy->getTrophy()->getTitle()}</a>.]]></item>
+               <item name="wcf.user.notification.com.woltlab.wcf.administration"><![CDATA[Administration]]></item>
+               <item name="wcf.user.notification.com.woltlab.wcf.user.registration.notification.registration"><![CDATA[Notify me of new user registrations]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation"><![CDATA[Moderation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation.queue.notification.comment"><![CDATA[Notify me when new comments are written in moderation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.moderation.queue.response.notification.commentResponse"><![CDATA[Notify me when new replies to comments are written in moderation]]></item>
@@ -4923,6 +4925,12 @@ your notifications on <a href="{link isEmail=true}{/link}">{PAGE_TITLE|language}
                <item name="wcf.user.notification.com.woltlab.wcf.articleComment.response.notification.commentResponse"><![CDATA[Notify me of new replies to my comments]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.articleComment.notification.comment"><![CDATA[Notify me of new comments on my articles]]></item>
                <item name="wcf.user.notification.pageComment.responseOwner.title"><![CDATA[New reply (Page)]]></item>
+               <item name="wcf.user.notification.userRegistration.title"><![CDATA[New user registration]]></item>
+               <item name="wcf.user.notification.userRegistration.title.stacked"><![CDATA[{#$count} new user registrations]]></item>
+               <item name="wcf.user.notification.userRegistration.message"><![CDATA[{@$author->getAnchorTag()} has registered.]]></item>
+               <item name="wcf.user.notification.userRegistration.message.stacked"><![CDATA[{if $count < 4}{@$authors[0]->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.]]></item>
+               <item name="wcf.user.notification.userRegistration.mail.plaintext"><![CDATA[{@$authorList} {if $count == 1}has{else}have{/if} registered.]]></item>
+               <item name="wcf.user.notification.userRegistration.mail.html"><![CDATA[<p>{@$authorList} {if $count == 1}has{else}have{/if} registered:</p>]]></item>
        </category>
        <category name="wcf.user.profile">
                <item name="wcf.user.profile.content.about.noPublicData"><![CDATA[{if $userID == $__wcf->getUser()->userID}You have not provided any details yet.{else}There are not any details visible to you.{/if}]]></item>