From 774ea272dabc534c4fa9e27c5dba43db8379b8ad Mon Sep 17 00:00:00 2001
From: =?utf8?q?Tim=20D=C3=BCsterhus?=
Date: Mon, 29 Jun 2020 15:47:32 +0200
Subject: [PATCH] Add NotificationUnsubscribeForm
see #3379
---
com.woltlab.wcf/page.xml | 14 ++
.../templates/notificationUnsubscribe.tpl | 29 ++++
.../NotificationUnsubscribeForm.class.php | 145 ++++++++++++++++++
wcfsetup/install/lang/de.xml | 14 +-
wcfsetup/install/lang/en.xml | 13 +-
5 files changed, 206 insertions(+), 9 deletions(-)
create mode 100644 com.woltlab.wcf/templates/notificationUnsubscribe.tpl
create mode 100644 wcfsetup/install/files/lib/form/NotificationUnsubscribeForm.class.php
diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml
index ade42ac8e1..bd765df539 100644
--- a/com.woltlab.wcf/page.xml
+++ b/com.woltlab.wcf/page.xml
@@ -189,6 +189,20 @@
Benachrichtigungseinstellungen
+
+ system
+ wcf\form\NotificationUnsubscribeForm
+ E-Mail-Benachrichtigungen abbestellen
+ Unsubscribe Email Notifications
+ com.woltlab.wcf.AccountManagement
+ 1
+
+ Unsubscribe Email Notifications
+
+
+ E-Mail-Benachrichtigungen abbestellen
+
+
system
wcf\form\RegisterForm
diff --git a/com.woltlab.wcf/templates/notificationUnsubscribe.tpl b/com.woltlab.wcf/templates/notificationUnsubscribe.tpl
new file mode 100644
index 0000000000..b15a2820cd
--- /dev/null
+++ b/com.woltlab.wcf/templates/notificationUnsubscribe.tpl
@@ -0,0 +1,29 @@
+{include file='header' __disableAds=true}
+
+{lang}wcf.user.notification.mail.unsubscribe.description{/lang}
+
+{include file='formError'}
+
+
+
+{include file='footer' __disableAds=true}
diff --git a/wcfsetup/install/files/lib/form/NotificationUnsubscribeForm.class.php b/wcfsetup/install/files/lib/form/NotificationUnsubscribeForm.class.php
new file mode 100644
index 0000000000..e948a5e279
--- /dev/null
+++ b/wcfsetup/install/files/lib/form/NotificationUnsubscribeForm.class.php
@@ -0,0 +1,145 @@
+
+ * @package WoltLabSuite\Core\Form
+ * @since 5.3
+ */
+class NotificationUnsubscribeForm extends AbstractForm {
+ /**
+ * user to unsubscribe
+ * @var User
+ */
+ public $user;
+
+ /**
+ * user provided verification token
+ * @var string
+ */
+ public $token = '';
+
+ /**
+ * whether this is a one-click request
+ * @var boolean
+ */
+ public $isOneClick = false;
+
+ /**
+ * notification event to unsubscribe
+ * @var UserNotificationEvent
+ */
+ public $event = null;
+
+ /**
+ * Disable security token validation.
+ */
+ protected function validateSecurityToken() {
+ // Do not validate the security token, the request is authenticated by
+ // the mail token.
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function readParameters() {
+ parent::readParameters();
+
+ if (isset($_REQUEST['userID'])) {
+ $this->user = new User(intval($_REQUEST['userID']));
+ if (!$this->user->userID) {
+ throw new IllegalLinkException();
+ }
+ }
+ else {
+ throw new IllegalLinkException();
+ }
+
+ if (isset($_REQUEST['token'])) {
+ $this->token = StringUtil::trim($_REQUEST['token']);
+ }
+ else {
+ throw new IllegalLinkException();
+ }
+
+ if (!empty($_REQUEST['eventID'])) {
+ $this->event = new UserNotificationEvent(intval($_REQUEST['eventID']));
+ if (!$this->event->eventID) {
+ throw new IllegalLinkException();
+ }
+ }
+
+ if (!$this->user || !hash_equals($this->user->notificationMailToken, $this->token)) {
+ throw new IllegalLinkException();
+ }
+
+ $this->isOneClick = (isset($_POST['List-Unsubscribe']) && $_POST['List-Unsubscribe'] === 'One-Click');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function save() {
+ parent::save();
+
+ if ($this->event !== null) {
+ $sql = "UPDATE wcf".WCF_N."_user_notification_event_to_user
+ SET mailNotificationType = ?
+ WHERE userID = ?
+ AND eventID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([
+ 'none',
+ $this->user->userID,
+ $this->event->eventID
+ ]);
+ }
+ else {
+ $sql = "UPDATE wcf".WCF_N."_user_notification_event_to_user
+ SET mailNotificationType = ?
+ WHERE userID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([
+ 'none',
+ $this->user->userID
+ ]);
+ }
+
+ $this->saved();
+
+ if ($this->isOneClick) {
+ header('HTTP/1.0 204 No Content');
+ exit;
+ }
+ else {
+ // redirect to url
+ HeaderUtil::delayedRedirect(LinkHandler::getInstance()->getLink(), WCF::getLanguage()->get('wcf.user.notification.mail.disabled'));
+ exit;
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign([
+ 'user' => $this->user,
+ 'token' => $this->token,
+ 'event' => $this->event,
+ ]);
+ }
+}
diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml
index 1c9a7fec2c..8403ed344d 100644
--- a/wcfsetup/install/lang/de.xml
+++ b/wcfsetup/install/lang/de.xml
@@ -5020,7 +5020,11 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
-
+
+
+
+
+
@@ -5033,14 +5037,14 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email}
{if LANGUAGE_USE_INFORMAL_VARIANT}Besuche deine{else}Besuchen Sie Ihre{/if} Benachrichtigungseinstellungen [URL:{link controller='NotificationSettings' isEmail=true}{/link}], um die
Benachrichtigungen auf {@PAGE_TITLE|language} [URL:{link isEmail=true}{/link}] nach {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Wünschen zu konfigurieren.
-Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} nur diese E-Mail-Benachrichtigung nicht mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen: {link controller='NotificationDisable' isEmail=true}eventID={@$event->eventID}&userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}.]]>
+Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} nur diese E-Mail-Benachrichtigung nicht mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen: {link controller='NotificationUnsubscribe' isEmail=true}eventID={@$event->eventID}&userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}.]]>
- Hallo {$mailbox->getUser()->username},]]>
- Diese E-Mail ist eine automatische Benachrichtigung. Bitte {if LANGUAGE_USE_INFORMAL_VARIANT}antworte{else}antworten Sie{/if} nicht auf diese E-Mail.
{if LANGUAGE_USE_INFORMAL_VARIANT}Besuche deine{else}Besuchen Sie Ihre{/if} Benachrichtigungseinstellungen, um die
Benachrichtigungen auf {PAGE_TITLE|language} nach {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Wünschen zu konfigurieren.
-Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} nur diese E-Mail-Benachrichtigung nicht mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen.
]]>
+Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} nur diese E-Mail-Benachrichtigung nicht mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen.
]]>
- getUser()->username},
@@ -5052,7 +5056,7 @@ Benachrichtigungen auf {PAGE_TITLE|lang
{if LANGUAGE_USE_INFORMAL_VARIANT}Besuche deine{else}Besuchen Sie Ihre{/if} Benachrichtigungseinstellungen [URL:{link controller='NotificationSettings' isEmail=true}{/link}], um die
Benachrichtigungen auf {@PAGE_TITLE|language} [URL:{link isEmail=true}{/link}] nach {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Wünschen zu konfigurieren.
-Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} keine E-Mail-Benachrichtigungen mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen: {link controller='NotificationDisable' isEmail=true}userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}.]]>
+Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} keine E-Mail-Benachrichtigungen mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen: {link controller='NotificationUnsubscribe' isEmail=true}userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}.]]>
- Hallo {@$mailbox->getUser()->username},
{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} derzeit insgesamt {#$notifications|count} ungelesene Benachrichtigung{if $notifications|count != 1}en{/if}, die älter als 24 Stunden {if $notifications|count == 1}ist{else}sind{/if}:
]]>
@@ -5063,7 +5067,7 @@ Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} keine E-Mail-Benachricht
{if LANGUAGE_USE_INFORMAL_VARIANT}Besuche deine{else}Besuchen Sie Ihre{/if} Benachrichtigungseinstellungen, um die
Benachrichtigungen auf {PAGE_TITLE|language} nach {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Wünschen zu konfigurieren.
-Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} keine E-Mail-Benachrichtigungen mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen.
]]>
+Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} keine E-Mail-Benachrichtigungen mehr erhalten {if LANGUAGE_USE_INFORMAL_VARIANT}möchtest{else}möchten{/if}, dann {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} diese direkt abbestellen.
]]>
- getAuthor()->userID}{if $guestTimesTriggered > 1}Gäste{else}Ein Gast{/if}{else}{@$event->getAuthor()->username} [URL:{link controller='User' object=$event->getAuthor() isEmail=true}{/link}]{/if}{if $count > 1 && $count < 4}{if $count == 2 && !$guestTimesTriggered} und {else}, {/if}{@$authors[1]->username} [URL:{link controller='User' object=$authors[1] isEmail=true}{/link}]{if $count == 3}{if !$guestTimesTriggered} und {else}, {/if}{@$authors[2]->username} [URL:{link controller='User' object=$authors[2] isEmail=true}{/link}]{/if}{elseif $count >= 4}{if $guestTimesTriggered},{else} und{/if} {#$count-1} weitere Benutzer{/if}{if $event->getAuthor()->userID && $guestTimesTriggered} und {if $guestTimesTriggered == 1}ein Gast{else}{#$guestTimesTriggered} Gäste{/if}{/if}]]>
- getAuthor()->userID}{if $guestTimesTriggered > 1}Gäste{else}Ein Gast{/if}{else}{$event->getAuthor()->username}{/if}{if $count > 1 && $count < 4}{if $count == 2 && !$guestTimesTriggered} und {else}, {/if}{$authors[1]->username}{if $count == 3}{if !$guestTimesTriggered} und {else}, {/if}{$authors[2]->username}{/if}{elseif $count >= 4}{if $guestTimesTriggered},{else} und{/if} {#$count-1} weitere Benutzer{/if}{if $event->getAuthor()->userID && $guestTimesTriggered} und {if $guestTimesTriggered == 1}ein Gast{else}{#$guestTimesTriggered} Gäste{/if}{/if}]]>
- {$authors[0]}{if $count != 1}{if $count == 2 && !$guestTimesTriggered} und {else}, {/if}{$authors[1]}{if $count == 3}{if !$guestTimesTriggered} und {else}, {/if} {$authors[2]}{/if}{/if}{if $guestTimesTriggered} und {plural value=$guestTimesTriggered one='ein Gast' other='# Gäste'}{/if}{else}{$authors[0]}{if $guestTimesTriggered},{else} und{/if} {#$others} weitere Benutzer {if $guestTimesTriggered}und {plural value=$guestTimesTriggered one='ein Gast' other='# Gäste'}{/if}{/if}]]>
diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml
index e7056031ed..39a403bec3 100644
--- a/wcfsetup/install/lang/en.xml
+++ b/wcfsetup/install/lang/en.xml
@@ -5016,6 +5016,11 @@ Open the link below to access the user profile:
+
+
+
+
+
@@ -5029,14 +5034,14 @@ Visit your notification settings [URL:{link controller='NotificationSettings' is
your notifications on {@PAGE_TITLE|language} [URL:{link isEmail=true}{/link}] as you wish.
If you only wish to disable this type of notification you can do so by visiting:
-{link controller='NotificationDisable' isEmail=true}eventID={@$event->eventID}&userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}]]>
+{link controller='NotificationUnsubscribe' isEmail=true}eventID={@$event->eventID}&userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}]]>
- Dear {$mailbox->getUser()->username},]]>
- This is an automatic notification, please do not reply to this email!
Visit your notification settings to configure
your notifications on {PAGE_TITLE|language} as you wish.
-You can disable only this type of notification as well.
]]>
+You can disable only this type of notification as well.
]]>
- getUser()->username},
@@ -5049,7 +5054,7 @@ Visit your notification settings [URL:{link controller='NotificationSettings' is
your notifications on {@PAGE_TITLE|language} [URL:{link isEmail=true}{/link}] as you wish.
If you wish to disable all email notifications you can do so by visiting:
-{link controller='NotificationDisable' isEmail=true}userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}]]>
+{link controller='NotificationUnsubscribe' isEmail=true}userID={@$mailbox->getUser()->userID}&token={@$mailbox->getUser()->notificationMailToken}{/link}]]>
- Dear {$mailbox->getUser()->username},
You currently have {#$notifications|count} unread notification{if $notifications|count != 1}s{/if} older than 24 hours:
]]>
@@ -5060,7 +5065,7 @@ If you wish to disable all email notifications you can do so by visiting:
Visit your notification settings to configure
your notifications on {PAGE_TITLE|language} as you wish.
-You can disable all email notifications as well.
]]>
+You can disable all email notifications as well.
]]>
- getAuthor()->userID}{if $guestTimesTriggered > 1}Guests{else}A guest{/if}{else}{@$event->getAuthor()->username} [URL:{link controller='User' object=$event->getAuthor() isEmail=true}{/link}]{/if}{if $count > 1 && $count < 4}{if $count == 2 && !$guestTimesTriggered} and {else}, {/if}{@$authors[1]->username} [URL:{link controller='User' object=$authors[1] isEmail=true}{/link}]{if $count == 3}{if !$guestTimesTriggered} and {else}, {/if}{@$authors[2]->username} [URL:{link controller='User' object=$authors[2] isEmail=true}{/link}]{/if}{elseif $count >= 4}{if $guestTimesTriggered},{else} and{/if} {#$count-1} other users{/if}{if $event->getAuthor()->userID && $guestTimesTriggered} and {if $guestTimesTriggered == 1}a guest{else}{#$guestTimesTriggered} guests{/if}{/if}]]>
- getAuthor()->userID}{if $guestTimesTriggered > 1}Guests{else}A guest{/if}{else}{$event->getAuthor()->username}{/if}{if $count > 1 && $count < 4}{if $count == 2 && !$guestTimesTriggered} and {else}, {/if}{$authors[1]->username}{if $count == 3}{if !$guestTimesTriggered} and {else}, {/if}{$authors[2]->username}{/if}{elseif $count >= 4}{if $guestTimesTriggered},{else} and{/if} {#$count-1} other users{/if}{if $event->getAuthor()->userID && $guestTimesTriggered} and {if $guestTimesTriggered == 1}a guest{else}{#$guestTimesTriggered} guests{/if}{/if}]]>
- {$authors[0]}{if $count != 1}{if $count == 2 && !$guestTimesTriggered} and {else}, {/if}{$authors[1]}{if $count == 3}{if !$guestTimesTriggered} and {else}, {/if} {$authors[2]}{/if}{/if}{if $guestTimesTriggered} and {plural value=$guestTimesTriggered one='a guest' other='# guests'}{/if}{else}{$authors[0]}{if $guestTimesTriggered},{else} and{/if} {#$others} other users {if $guestTimesTriggered}and {plural value=$guestTimesTriggered one='a guest' other='# guests'}{/if}{/if}]]>
--
2.20.1