Esempio n. 1
0
def user_activation_email_page(request, pr_access_code=None):
    # Find the user or error.
    try:
        me = User.objects.get(pr_access_code=pr_access_code)
        if not me.has_pr_code_expired():
            # Indicate that the account is active.
            me.was_activated = True
            me.save()
        else:
            # Erro message indicating code expired.
            logger.info("Access code expired.")
            raise PermissionDenied(_('Access code expired.'))
    except User.DoesNotExist:
        logger.info("Wrong access code.")
        raise PermissionDenied(_('Wrong access code.'))

    # Generate the data.
    url = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL+settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN+"/activate/"+str(pr_access_code)
    web_view_url = reverse_with_full_domain(
        reverse_url_id='mikaponics_activate_email',
        resolve_url_args=[pr_access_code]
    )
    param = {
        'constants': constants,
        'url': url,
        'web_view_url': web_view_url,
        'me': me
    }

    # DEVELOPERS NOTE:
    # - When copying the "Sunday" open source email theme into our code, we will
    #   need to use a formatter to inline the CSS.
    # - https://templates.mailchimp.com/resources/inline-css/

    return render(request, 'account/email/user_activation_email_view.html', param)
    def begin_processing(self, user):
        # Generate the data.
        url = settings.MIKAPONICS_BACKEND_HTTP_PROTOCOL + settings.MIKAPONICS_BACKEND_HTTP_DOMAIN + "/en/admin/foundation/user/" + str(
            user.id) + "/change/"
        web_view_url = reverse_with_full_domain(
            reverse_url_id='mikaponics_user_was_created_email',
            resolve_url_args=[user.id])
        subject = "New user to Mikaponics!"
        param = {
            'user': user,
            'url': url,
            'web_view_url': web_view_url,
            'constants': constants
        }

        # Plug-in the data into our templates and render the data.
        text_content = render_to_string(
            'account/email/user_was_created_email.txt', param)
        html_content = render_to_string(
            'account/email/user_was_created_email.html', param)

        # Generate our address.
        from_email = settings.DEFAULT_FROM_EMAIL
        to = get_staff_email_addresses()

        # Send the email.
        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")
        msg.send()
Esempio n. 3
0
    def begin_processing(self, me):
        pr_access_code = me.generate_pr_code()

        # Generate the data.
        url = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL + settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN + "/activate/" + str(
            pr_access_code)
        web_view_url = reverse_with_full_domain(
            reverse_url_id='mikaponics_activate_email',
            resolve_url_args=[pr_access_code])
        subject = "Welcome to Mikaponics!"
        param = {
            'me': me,
            'url': url,
            'web_view_url': web_view_url,
            'constants': constants
        }

        # Plug-in the data into our templates and render the data.
        text_content = render_to_string(
            'account/email/user_activation_email_view.txt', param)
        html_content = render_to_string(
            'account/email/user_activation_email_view.html', param)

        # Generate our address.
        from_email = settings.DEFAULT_FROM_EMAIL
        to = [me.email]

        # Send the email.
        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")
        msg.send()
Esempio n. 4
0
def user_was_created_email_page(request, user_id):
    # Defensive Code: Make sure the user information are protected.
    if request.user.is_authenticated == False:
        raise PermissionDenied(_('You are not authenticated.'))
    if request.user.is_staff == False:
        raise PermissionDenied(_('You are not a staff member.'))

    # Find the user or error.
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        logger.info("Wrong access code.")
        raise PermissionDenied(_('Wrong user ID.'))

    # Generate the data.
    url = settings.MIKAPONICS_BACKEND_HTTP_PROTOCOL+settings.MIKAPONICS_BACKEND_HTTP_DOMAIN+"/en/admin/foundation/user/"+str(user_id)+"/change/"
    web_view_url = reverse_with_full_domain(
        reverse_url_id='mikaponics_user_was_created_email',
        resolve_url_args=[user.id]
    )
    param = {
        'constants': constants,
        'url': url,
        'web_view_url': web_view_url,
        'user': user
    }

    # DEVELOPERS NOTE:
    # - When copying the "Sunday" open source email theme into our code, we will
    #   need to use a formatter to inline the CSS.
    # - https://templates.mailchimp.com/resources/inline-css/

    return render(request, 'account/email/user_was_created_email.html', param)
Esempio n. 5
0
def onboarded_email_page(request, pk=None):
    user = User.objects.filter(pk=pk).first()
    if user is None:
        raise PermissionDenied(_('Does not exist.'))

    # Generate the data.
    url = settings.MIKAPONICS_BACKEND_HTTP_PROTOCOL + settings.MIKAPONICS_BACKEND_HTTP_DOMAIN + "/en/admin/foundation/user/" + str(
        user.id) + "/change/"
    web_view_url = reverse_with_full_domain(
        reverse_url_id='mikaponics_onboarded_email',
        resolve_url_args=[user.id])

    # Get the parameter.
    param = {
        'constants': constants,
        'url': url,
        'web_view_url': web_view_url,
        'user': user,
    }
    # # DEVELOPERS NOTE:
    # # - When copying the "Sunday" open source email theme into our code, we will
    # #   need to use a formatter to inline the CSS.
    # # - https://templates.mailchimp.com/resources/inline-css/

    return render(request, 'store/emails/onboarded_email_view.html', param)
Esempio n. 6
0
def receipt_email_page(request, pk=None):
    invoice = Invoice.objects.filter(pk=pk).first()
    if invoice is None:
        raise PermissionDenied(_('Does not exist.'))

    # Generate the data.
    url = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL + settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN + "/invoice/" + invoice.slug
    web_view_url = reverse_with_full_domain(
        reverse_url_id='mikaponics_invoice_receipt_email',
        resolve_url_args=[invoice.id])

    # Get the parameter.
    param = {
        'constants': constants,
        'url': url,
        'web_view_url': web_view_url,
        'me': request.user,
        'invoice': invoice,
    }
    # # DEVELOPERS NOTE:
    # # - When copying the "Sunday" open source email theme into our code, we will
    # #   need to use a formatter to inline the CSS.
    # # - https://templates.mailchimp.com/resources/inline-css/

    return render(request, 'store/emails/receipt_email_view.html', param)
Esempio n. 7
0
    def begin_processing(self, invoice):
        # Generate the data.
        url = settings.MIKAPONICS_BACKEND_HTTP_PROTOCOL+settings.MIKAPONICS_BACKEND_HTTP_DOMAIN+"/en/admin/foundation/user/"+str(invoice.user.id)+"/change/"
        web_view_url = reverse_with_full_domain(
            reverse_url_id='mikaponics_invoice_receipt_email',
            resolve_url_args=[invoice.id]
        )

        # Get the parameter.
        subject = "Mikaponics: Customer made purchase"
        param = {
            'constants': constants,
            'url': url,
            'web_view_url': web_view_url,
            'me': invoice.user,
            'invoice': invoice,
        }

        # Plug-in the data into our templates and render the data.
        text_content = render_to_string('store/emails/receipt_email_view.txt', param)
        html_content = render_to_string('store/emails/receipt_email_view.html', param)

        # Generate our address.
        from_email = settings.DEFAULT_FROM_EMAIL
        to = get_staff_email_addresses()

        # Send the email.
        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")
        msg.send()
    def begin_processing(self, alert):
        me = alert.production.user
        production = alert.production

        # Generate the links.
        url = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL + settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN + alert.production.get_absolute_url(
        )
        web_view_url = reverse_with_full_domain(
            reverse_url_id='mikaponics_production_alert_items_email',
            resolve_url_args=[alert.id])
        subject = "Mikaponics: Alert Notification"
        param = {
            'alert': alert,
            'url': url,
            'web_view_url': web_view_url,
            'me': me
        }

        # For debugging purposes only.
        print(
            "---------------------------------------------------------------")
        print("URL", url)
        print("WEB URL", web_view_url)
        print(
            "---------------------------------------------------------------")

        # DEVELOPERS NOTE:
        # https://templates.mailchimp.com/resources/inline-css/

        # Plug-in the data into our templates and render the data.
        text_content = render_to_string(
            'alert/email/production_alert_email_view.txt', param)
        html_content = render_to_string(
            'alert/email/production_alert_email_view.html', param)

        # Generate our address.
        from_email = settings.DEFAULT_FROM_EMAIL
        to = [me.email]

        # Send the email.
        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")
        msg.send()

        # For debugging purposes only.
        self.stdout.write(
            self.style.SUCCESS(
                _('%(dt)s | SPAE | Sent alert email to %(email)s.') % {
                    'dt': str(timezone.now()),
                    'email': me.email
                }))
    def get_context_data(self, **kwargs):
        # Get the context of this class based view.
        context = super().get_context_data(**kwargs)

        alert = context['alert']

        # Update our context.
        context['me'] = self.request.user
        context['alert'] = alert
        context['url'] = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL+settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN+alert.instrument.get_absolute_url()
        context['web_view_url'] = reverse_with_full_domain(
            reverse_url_id='mikaponics_instrument_alert_items_email',
            resolve_url_args=[alert.id]
        )

        # Return our modified context.
        return context
Esempio n. 10
0
    def begin_processing(self, me):
        pr_access_code = me.generate_pr_code()

        # Generate the links.
        url = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL + settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN + "/reset-password/" + str(
            pr_access_code)
        web_view_url = reverse_with_full_domain(
            reverse_url_id='mikaponics_reset_password_email',
            resolve_url_args=[pr_access_code])
        subject = "Mikaponics: Password Reset"
        param = {'url': url, 'web_view_url': web_view_url, 'me': me}

        # For debugging purposes only.
        print(
            "---------------------------------------------------------------")
        print("URL", url)
        print("WEB URL", web_view_url)
        print(
            "---------------------------------------------------------------")

        # DEVELOPERS NOTE:
        # https://templates.mailchimp.com/resources/inline-css/

        # Plug-in the data into our templates and render the data.
        text_content = render_to_string(
            'account/email/reset_password_email_view.txt', param)
        html_content = render_to_string(
            'account/email/reset_password_email_view.html', param)

        # Generate our address.
        from_email = settings.DEFAULT_FROM_EMAIL
        to = [me.email]

        # Send the email.
        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")
        msg.send()

        self.stdout.write(
            self.style.SUCCESS(
                _('Mikaponics: Sent welcome email to %s.') % str(me.email)))
Esempio n. 11
0
    def begin_processing(self, invoice, override_email):
        # Generate the data.
        url = settings.MIKAPONICS_FRONTEND_HTTP_PROTOCOL+settings.MIKAPONICS_FRONTEND_HTTP_DOMAIN+"/invoice/"+invoice.slug;
        web_view_url = reverse_with_full_domain(
            reverse_url_id='mikaponics_invoice_receipt_email',
            resolve_url_args=[invoice.id]
        )

        # Get the parameter.
        subject = "Mikaponics: Your Receipt is Ready"
        param = {
            'constants': constants,
            'url': url,
            'web_view_url': web_view_url,
            'me': invoice.user,
            'invoice': invoice,
        }

        # Plug-in the data into our templates and render the data.
        text_content = render_to_string('store/emails/receipt_email_view.txt', param)
        html_content = render_to_string('store/emails/receipt_email_view.html', param)

        # Generate our address.
        from_email = settings.DEFAULT_FROM_EMAIL
        to = [invoice.user.email,]

        # Override the destination email if we have to.
        if override_email:
            try:
                validate_email(override_email) # Defensive code
                if '@' not in override_email:
                    to = override_email
            except Exception as e:
                pass # Skip this step on error.

        # Send the email.
        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")
        msg.send()