Example #1
0
    def send_email(self):
        """
        Email admins when new account requests are received.
        """

        # In the case that the account registration request is tied to a department,
        # we'll prompt the department admin to approve the request, which will send
        # an invite on the admin's behalf

        if self.object.department:
            to = [
                x.email
                for x in self.object.department.get_department_admins()
            ]
            body = loader.render_to_string(
                'contact/account_request_department_admin_email.txt',
                dict(contact=self.object, site=Site.objects.get_current()))
        else:
            to = [self.object.email]
            body = loader.render_to_string(
                'contact/account_request_email.txt',
                dict(STATIC_URL=settings.STATIC_URL,
                     contact=self.object,
                     site=Site.objects.get_current()))
        email_message = EmailMultiAlternatives(
            '{} - Access.'.format(Site.objects.get_current().name),
            body,
            settings.DEFAULT_FROM_EMAIL,
            to,
            cc=['*****@*****.**'],
            reply_to=['*****@*****.**'])
        send_mail.delay(email_message)
Example #2
0
    def post(self, *args, **kwargs):
        self.object = self.get_object()

        form = DepartmentUserApprovalForm(self.request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']
            req = AccountRequest.objects.get(email=email)

            if form.cleaned_data['approved']:
                req.approve(self.request.user)
                messages.add_message(self.request, messages.SUCCESS, 'Invited {} to FireCARES.'.format(email))
                send_invites([dict(email=email, department_id=self.object.id)], self.request)
            else:
                req.deny(self.request.user)
                messages.add_message(self.request, messages.SUCCESS, 'Denied {}\'s request for an account on FireCARES.'.format(email))

                body = form.cleaned_data['message']
                context = dict(account_request=req, message=body, site=get_current_site(self.request))
                body = loader.render_to_string('registration/department_account_request_email.txt', context)
                subject = 'Your FireCARES account request'
                email_message = EmailMultiAlternatives(subject, body, settings.DEFAULT_FROM_EMAIL, [req.email])
                send_mail.delay(email_message)

        return redirect(self.object)
Example #3
0
    def send_email(self, contact):
        body = loader.render_to_string('contact/contact_admin_email.txt', dict(contact=contact))

        email_message = EmailMultiAlternatives('Contact request submitted',
                                               body,
                                               settings.DEFAULT_FROM_EMAIL,
                                               [x[1] for x in settings.ADMINS])
        send_mail.delay(email_message)
Example #4
0
    def send_email(self, contact):
        body = loader.render_to_string('contact/contact_admin_email.txt', dict(contact=contact))

        email_message = EmailMultiAlternatives('Contact request submitted',
                                               body,
                                               settings.DEFAULT_FROM_EMAIL,
                                               [x[1] for x in settings.ADMINS],
                                               reply_to=[contact.email])
        send_mail.delay(email_message)
Example #5
0
 def send_email(self):
     """
     Email admins when new account requests are received.
     """
     body = loader.render_to_string('contact/account_request_email.txt', dict(contact=self.object))
     email_message = EmailMultiAlternatives('New account request received.',
                                            body,
                                            settings.DEFAULT_FROM_EMAIL,
                                            [x[1] for x in settings.ADMINS])
     send_mail.delay(email_message)
Example #6
0
 def send_email(self):
     """
     Email admins when new account requests are received.
     """
     body = loader.render_to_string('contact/account_request_email.txt',
                                    dict(contact=self.object))
     email_message = EmailMultiAlternatives('New account request received.',
                                            body,
                                            settings.DEFAULT_FROM_EMAIL,
                                            [x[1] for x in settings.ADMINS])
     send_mail.delay(email_message)
Example #7
0
 def _send_email(self):
     """
     Email admins when new feedback are received
     """
     to = [x[1] for x in settings.DATA_FEEDBACK_EMAILS]
     body = loader.render_to_string('contact/data_feedback.txt', dict(contact=self.object))
     email_message = EmailMultiAlternatives('{} - New feedback received.'.format(Site.objects.get_current().name),
                                            body,
                                            settings.DEFAULT_FROM_EMAIL,
                                            to,
                                            reply_to=[self.object.user.email])
     send_mail.delay(email_message)
Example #8
0
    def send_mail(self, subject, email_template_name, context, from_email,
                  to_email, html_email_template_name=None):
        """
        Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
        """

        body = loader.render_to_string(email_template_name, context)

        email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
        if html_email_template_name is not None:
            html_email = loader.render_to_string(html_email_template_name, context)
            email_message.attach_alternative(html_email, 'text/html')

        send_mail.delay(email_message)
Example #9
0
    def send_mail(self, subject_template_name, email_template_name,
                  context, from_email, to_email, html_email_template_name=None):
        """
        Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
        """
        subject = loader.render_to_string(subject_template_name, context)

        # Email subject *must not* contain newlines
        subject = ''.join(subject.splitlines())
        body = loader.render_to_string(email_template_name, context)

        email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
        if html_email_template_name is not None:
            html_email = loader.render_to_string(html_email_template_name, context)
            email_message.attach_alternative(html_email, 'text/html')

        send_mail.delay(email_message)
Example #10
0
    def send_mail(self,
                  subject,
                  email_template_name,
                  context,
                  from_email,
                  to_email,
                  html_email_template_name=None):
        """
        Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
        """

        body = loader.render_to_string(email_template_name, context)

        email_message = EmailMultiAlternatives(subject, body, from_email,
                                               [to_email])
        if html_email_template_name is not None:
            html_email = loader.render_to_string(html_email_template_name,
                                                 context)
            email_message.attach_alternative(html_email, 'text/html')

        send_mail.delay(email_message)
Example #11
0
    def form_valid(self, form):
        department = FireDepartment.objects.get(id=form.data.get('department'))
        association = DepartmentAssociationRequest.objects.create(
            department=department, user=self.request.user)

        # Send email to DEPARTMENT_ADMIN_VERIFIERS
        context = dict(association=association,
                       email=association.user.email,
                       username=association.user.username,
                       site=get_current_site(self.request))
        body = loader.render_to_string('registration/verify_admin_email.txt',
                                       context)
        subject = 'Department administrator request - {email}'.format(
            email=association.user.email)
        email_message = EmailMultiAlternatives(
            subject, body, settings.DEFAULT_FROM_EMAIL,
            [x[1] for x in settings.DEPARTMENT_ADMIN_VERIFIERS])
        send_mail.delay(email_message)

        self.request.session[
            'message'] = 'Your request has been received, an administrator will contact you shortly to verify your information.  In the meantime, feel free to peruse the FireCARES site!'
        return redirect('show_message')
Example #12
0
    def post(self, *args, **kwargs):
        body = json.loads(self.request.body)
        req = DepartmentAssociationRequest.objects.get(id=body.get('id'))
        if body.get('approve', False):
            req.approve(self.request.user)
        else:
            req.deny(self.request.user)

        # Send email reponse to requesting user of acceptance or denial
        context = dict(association=req,
                       message=body.get('message'),
                       site=get_current_site(self.request))
        body = loader.render_to_string(
            'registration/association_response_email.txt', context)
        subject = 'Department administrator request'
        email_message = EmailMultiAlternatives(subject, body,
                                               settings.DEFAULT_FROM_EMAIL,
                                               [req.user.email])
        send_mail.delay(email_message)

        req.refresh_from_db()

        return JsonResponse(serialize_association_request(req))
Example #13
0
    def send_mail(self,
                  subject_template_name,
                  email_template_name,
                  context,
                  from_email,
                  to_email,
                  html_email_template_name=None):
        """
        Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
        """
        subject = loader.render_to_string(subject_template_name, context)

        # Email subject *must not* contain newlines
        subject = ''.join(subject.splitlines())
        body = loader.render_to_string(email_template_name, context)

        email_message = EmailMultiAlternatives(subject, body, from_email,
                                               [to_email])
        if html_email_template_name is not None:
            html_email = loader.render_to_string(html_email_template_name,
                                                 context)
            email_message.attach_alternative(html_email, 'text/html')

        send_mail.delay(email_message)
Example #14
0
    def post(self, request, **kwargs):
        self.object = self.get_object()
        section = request.POST.get('form')

        if section == 'whitelist':
            items = zip(request.POST.getlist('id'),
                        request.POST.getlist('email_or_domain'),
                        request.POST.getlist('give_curator'),
                        request.POST.getlist('give_admin'))

            # Delete any whitelist items that don't come back
            RegistrationWhitelist.for_department(self.object).exclude(id__in=[int(i[0]) for i in items if i[0]]).delete()

            # Create new items
            for i in filter(lambda x: x[0] == '', items):
                give_curator = 'change_firedepartment' if i[2] == 'true' else ''
                give_admin = 'admin_firedepartment' if i[3] == 'true' else ''
                reg = RegistrationWhitelist.objects.create(department=self.object,
                                                           email_or_domain=i[1],
                                                           created_by=request.user,
                                                           permission=','.join([give_curator, give_admin]))
                # Also, send email IF it's an individual email address that is being whitelisted
                if not reg.is_domain_whitelist:
                    context = dict(whitelist=reg, site=get_current_site(request))
                    body = loader.render_to_string('registration/email_has_been_whitelisted.txt', context)
                    subject = 'Your email address is allowed to login to or register with FireCARES'
                    email_message = EmailMultiAlternatives(
                        subject,
                        body,
                        settings.DEFAULT_FROM_EMAIL,
                        [reg.email_or_domain],
                        reply_to=['*****@*****.**'])
                    send_mail.delay(email_message)

            messages.add_message(request, messages.SUCCESS, 'Updated whitelisted registration emails addresses/domains for this department in FireCARES.')
        elif section == 'users':
            users = self.object.get_users_with_permissions()

            can_admin_users = request.POST.getlist('can_admin')
            can_change_users = request.POST.getlist('can_change')
            skipped = set([])

            for user in can_admin_users:
                cur = User.objects.filter(email=user).first()
                if not cur:
                    skipped.add(user)
                    continue
                self.object.add_admin(cur)
            for user in users:
                if user.email not in can_admin_users:
                    self.object.remove_admin(user)

            for user in can_change_users:
                cur = User.objects.filter(email=user).first()
                if not cur:
                    skipped.add(user)
                    continue
                self.object.add_curator(cur)
            for user in users:
                if user.email not in can_change_users:
                    self.object.remove_curator(user)

            if skipped:
                messages.add_message(request, messages.ERROR, 'Unable to find users with email addresses, skipping: {}'.format(', '.join(skipped)))

            messages.add_message(request, messages.SUCCESS, 'Updated department\'s authorized users.')
        else:
            return HttpResponseBadRequest()
        return redirect(self.object)