Skip to content

Commit

Permalink
Merge pull request #57 from RegioneER/issue_28429
Browse files Browse the repository at this point in the history
Add confirm subscription with POST
  • Loading branch information
cekk authored Jan 9, 2025
2 parents e29dacc + e0d82b7 commit 511bd45
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
metal:use-macro="here/main_template/macros/master"
i18n:domain="rer.newsletter">

<metal:block metal:fill-slot="style_slot">
</metal:block>

<metal:block metal:fill-slot="javascript_head_slot">
</metal:block>

<!-- disattivo le portlet in questa view -->
<metal:override fill-slot="top_slot"
tal:define="disable_column_one python:request.set('disable_plone.leftcolumn',1);
disable_column_two python:request.set('disable_plone.rightcolumn',1);"/>

<body>
<metal:description fill-slot="content-description">
<p class="discreet"
i18n:translate="confirm_subscribe_legend">
Clicking here, you will be subscribed to this channel.
</p>
</metal:description>
<metal:content-core fill-slot="content-core">
<form action="${context/absolute_url}/confirm-subscription"
method="POST">
<input type="hidden" value="${request/secret}" name="secret" id="secret" />
<input type="hidden" value="true" name="submitted" id="submitted" />
<span tal:replace="structure context/@@authenticator/authenticator"/>
<div class="formControls">
<input class="context focus" type="submit" value="Confirm" i18n:attributes="value">
</div>
</form>
</metal:content-core>
</body>

Expand Down
33 changes: 21 additions & 12 deletions src/rer/newsletter/browser/channel/users/confirm_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rer.newsletter import _
from rer.newsletter.adapter.subscriptions import IChannelSubscriptions
from rer.newsletter.contentrules.events import SubscriptionEvent
from rer.newsletter.utils import OK
from rer.newsletter.utils import OK, ALREADY_ACTIVE
from rer.newsletter.utils import compose_sender
from rer.newsletter.utils import get_site_title
from zope.component import getMultiAdapter
Expand Down Expand Up @@ -53,6 +53,10 @@ def _sendGenericMessage(self, template, receiver, message, message_title):
return OK

def __call__(self):
submitted = self.request.form.get("submitted", "")
if not submitted or self.request.method != "POST":
return super(ConfirmSubscription, self).__call__()

secret = self.request.get("secret")

response = None
Expand All @@ -70,30 +74,35 @@ def __call__(self):
message_title="Iscrizione confermata",
)
status = _(
u"generic_activate_message_success",
default=u'Ti sei iscritto alla newsletter ${channel} del portale "${site}".',
"generic_activate_message_success",
default='Ti sei iscritto alla newsletter ${channel} del portale "${site}".',
mapping=dict(
channel=self.context.title, site=get_site_title()
),
)
if response == OK:
api.portal.show_message(
message=status, request=self.request, type=u"info"
message=status, request=self.request, type="info"
)
else:
logger.error(
'Unable to subscribe user with token "{token}" on channel {channel}.'.format( # noqa
token=secret, channel=self.context.absolute_url()
)
)
msg = _(
"unable_to_subscribe",
default="Unable to subscribe to this channel."
" Please contact site administrator.",
)
if response == ALREADY_ACTIVE:
msg = _(
"already_active",
default="You are already subscribed to this channel.",
)
api.portal.show_message(
message=_(
"unable_to_subscribe",
default=u"Unable to subscribe to this channel."
u" Please contact site administrator.",
),
message=msg,
request=self.request,
type=u"error",
type="error",
)

return self.render()
return self.request.response.redirect(self.context.absolute_url())
Loading

0 comments on commit 511bd45

Please sign in to comment.