Exemple #1
0
 def unsubscribe_url(self):
     # Use prefix='/' for reverse here instead of relying on get_script_prefix inside of
     # reverse. This is because this method is called by management commands which
     # have no concept of get_script_prefix().
     return '?'.join([
         settings.PROJECT_URL + reverse('manager-recipient-subscriptions', kwargs={'pk':self.pk}, prefix='/'),
         urllib.urlencode({
             'mac'      :calc_unsubscribe_mac(self.pk)
         })
     ])
Exemple #2
0
	def _test_unsubscribe(self):
		'''
			Test the unsubcribe functionality. Must be called in the context of an email instance.
		'''
		client   = Client()
		response = client.get('?'.join([
			reverse('manager-email-unsubscribe'),
			urllib.urlencode({
				'recipient':self.recipient.pk,
				'email'    :self.email.pk,
				'mac'      :calc_unsubscribe_mac(self.recipient.pk, self.email.pk)
			})
		]))
		self.assertTrue(response.status_code == 200)
		self.assertTrue(self.email.unsubscriptions.count() == 1)
Exemple #3
0
    def _test_unsubscribe(self):
        '''
			Test the unsubcribe functionality. Must be called in the context of an email instance.
		'''
        client = Client()
        response = client.get('?'.join([
            reverse('manager-email-unsubscribe'),
            urllib.parse.urlencode({
                'recipient':
                self.recipient.pk,
                'email':
                self.email.pk,
                'mac':
                calc_unsubscribe_mac(self.recipient.pk, self.email.pk)
            })
        ]))
        self.assertTrue(response.status_code == 200)
        self.assertTrue(self.email.unsubscriptions.count() == 1)
Exemple #4
0
	def get_object(self, *args, **kwargs):
		mac          = self.request.GET.get('mac', None)

		recipient_id = self.request.GET.get('recipient', None)
		email_id     = self.request.GET.get('email',     None)

		# Old style unsubscribe
		if recipient_id is not None and email_id is not None:
			try:
				recipient = Recipient.objects.get(pk=recipient_id)
			except Recipient.DoesNotExist:
				raise PermissionDenied
			if mac is None or mac != calc_unsubscribe_mac_old(recipient_id, email_id):
				raise PermissionDenied
		else:
			recipient         = super(RecipientSubscriptionsUpdateView, self).get_object()
			# Validate MAC
			if mac is None or mac != calc_unsubscribe_mac(recipient.pk):
				raise PermissionDenied
		return recipient
Exemple #5
0
 def hmac_hash(self):
     return calc_unsubscribe_mac(self.pk)