def begin_processing(self, me):
        pr_access_code = me.generate_pr_code()

        # Generate the data.
        url = reverse_with_full_domain(
            reverse_url_id='workery_user_activation_detail',
            resolve_url_args=[pr_access_code])
        web_view_url = reverse_with_full_domain(
            reverse_url_id='workery_activate_email',
            resolve_url_args=[pr_access_code])
        subject = "Welcome to Over 55 Inc!"
        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(
            'shared_auth/email/user_activation_email_view.txt', param)
        html_content = render_to_string(
            'shared_auth/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()
Exemplo n.º 2
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 = SharedUser.objects.get(id=user_id)
    except SharedUser.DoesNotExist:
        logger.info("Wrong access code.")
        raise PermissionDenied(_('Wrong user ID.'))

    # Generate the data.
    url = settings.NWAPP_BACKEND_HTTP_PROTOCOL + settings.NWAPP_BACKEND_HTTP_DOMAIN + "/en/admin/foundation/user/" + str(
        user_id) + "/change/"
    web_view_url = reverse_with_full_domain(
        reverse_url_id='nwapp_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)
    def begin_processing(self, me):
        pr_access_code = me.generate_pr_code()

        # Generate the links.
        url = reverse_with_full_domain(
            reverse_url_id='at_reset_password_master',
            resolve_url_args=[pr_access_code])
        web_view_url = reverse_with_full_domain(
            reverse_url_id='at_reset_password_email',
            resolve_url_args=[pr_access_code])
        subject = "Over55: 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(
            'shared_auth/email/reset_password_email.txt', param)
        html_content = render_to_string(
            'shared_auth/email/reset_password_email.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(
                _('AT: Sent welcome email to %s.') % str(me.email)))
Exemplo n.º 4
0
def user_activation_email_page(request, pr_access_code=None):
    # Find the user or error.
    try:
        me = SharedUser.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 SharedUser.DoesNotExist:
        logger.info("Wrong access code.")
        raise PermissionDenied(_('Wrong access code.'))

    # Generate the data.
    url = reverse_with_full_domain(
        reverse_url_id='workery_user_activation_detail',
        resolve_url_args=[pr_access_code])
    web_view_url = reverse_with_full_domain(
        reverse_url_id='workery_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, 'shared_auth/email/user_activation_email_view.html',
                  param)