Beispiel #1
0
 def form_valid(self, form):
     django_user = form.save()
     if self.msg:
         # updated user info for new user trying to send an email first time
         return redirect('confirm', token=self.msg.token_key)
     elif self.user:
         # updated user info for already existing user
         emailer.NoReply(django_user).address_changed().send()
         self.request.session['address_updated'] = True
         return redirect('complete-verify', token=self.user.token_key)
     else:
         # created new user on initial web signup
         emailer.NoReply(django_user).signup_confirm().send()
         return super().form_valid(form)
Beispiel #2
0
    def process(self):

        django_user = DjangoUser.objects.filter(
            email=self.cleaned_data['email']).first()
        if django_user:
            if self.cleaned_data['submit_type'] == 'update_address':
                django_user.user.token.get().reset()
                emailer.NoReply(django_user).address_change_request().send()
            elif self.cleaned_data['submit_type'] == 'remind_reps':
                emailer.NoReply(django_user).remind_reps().send()
            return 'Check your inbox! We just sent an email to ' + self.cleaned_data[
                'email'] + '.'
        else:
            return "The email you've entered doesn't exist in our system. Have you signed up?"
Beispiel #3
0
def send_to_phantom_of_the_capitol(self, msg_id=None, msgleg_id=None, force=False):
    """

    @param self:
    @type self:
    @param msg_id:
    @type msg_id:
    @param msgleg_id:
    @type msgleg_id:
    @param force:
    @type force:
    @return:
    @rtype:
    """
    if settings.CONFIG_DICT['email']['submit_to_webform'] or force:
        try:
            from emailcongress.models import Message, MessageLegislator
            if msgleg_id is not None:
                MessageLegislator.objects.get(id=msgleg_id).send()
            elif msg_id is not None:
                msg = Message.objects.get(pk=msg_id)
                msg.send()
                if msg.get_send_status() == 'sent' or self.request.retries >= self.max_retries:
                    emailer.NoReply(msg.user_message_info.user.django_user).send_status(msg.to_legislators, msg).send()
                else:
                    raise self.retry(exc=Exception)
        except:
            raise Exception(traceback.format_exc())
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        try:
            inbound = PostmarkInbound(json=request.body.decode('utf-8'))
            django_user, user, umi = User.get_or_create_user_from_email(inbound.sender()['Email'].lower())

            # get message id for email threading
            if 'Headers' in inbound.source and inbound.headers('Message-ID') is not None:
                msg_id = inbound.headers('Message-ID')
            else:
                msg_id = inbound.message_id()

            if not Message.objects.filter(email_uid=inbound.message_id()).exists():

                new_msg = Message.objects.create(created_at=inbound.send_date(),
                                                 to_originally=[r['Email'].lower() for r in inbound.to()],
                                                 subject=inbound.subject(),
                                                 msgbody=inbound.text_body(),
                                                 email_uid=msg_id,
                                                 user_message_info=umi)

                # first time user or it has been a long time since they've updated their address info
                if umi.must_update_address_info():
                    emailer.NoReply(django_user).email_confirm(new_msg).send()
                    return JsonResponse({'status': 'User must accept tos / update their address info.'})
                else:
                    MessageViewSet.process_inbound_message(django_user, umi, new_msg)
                    return JsonResponse({'status': 'Message queued for processing.'})
            else:
                return JsonResponse({'status': 'Message with provided ID already received.'})
                # TODO robust error handling
        except:
            client.captureException()
            return 'Failure', 500
Beispiel #5
0
    def process_inbound_message(django_user, umi, msg, test=False):
        try:
            msg.update_status()

            leg_buckets = models.Legislator.get_leg_buckets_from_emails(
                umi.members_of_congress, msg.to_originally)
            msg.set_legislators(leg_buckets['contactable'])

            if msg.has_legislators and msg.is_free_to_send():
                msg.queue_to_send()
                emailer.NoReply(django_user).message_queued(msg).send(
                    test=test)
            elif not msg.is_free_to_send():
                emailer.NoReply(django_user).over_rate_limit(msg).send(
                    test=test)
            elif leg_buckets['does_not_represent'] or leg_buckets[
                    'non_existent']:
                emailer.NoReply(django_user).message_undeliverable(
                    leg_buckets, msg).send(test=test)

            return True
        except:
            return traceback.format_exc()
Beispiel #6
0
 def get(self, request, *args, **kwargs):
     if self.umi and self.umi.accept_tos is None:
         self.umi.accept_tos = timezone.now()
         self.umi.save()
         emailer.NoReply(self.user.django_user).signup_success().send()
     return super().get(request, *args, **kwargs)
Beispiel #7
0
 def form_valid(self, form):
     form.complete_and_queue_message()
     emailer.NoReply(self.user.django_user).message_queued(form.instance).send()
     return super().form_valid(form)