Exemple #1
0
def process_accesscode_request(request, pk):

    obj = WhitepaperAccessRequest.objects.get(pk=pk)
    context = {
        'obj': obj,
    }

    if obj.processed:
        raise

    if request.POST.get('submit', False):
        invitecode = token_hex(16)[:29]

        AccessCodes.objects.create(
            invitecode=invitecode,
            maxuses=1,
        )
        obj.processed = True
        obj.save()

        from_email = settings.PERSONAL_CONTACT_EMAIL
        to_email = obj.email
        cur_language = translation.get_language()
        try:
            setup_lang(to_email)
            subject = request.POST.get('subject')
            body = request.POST.get('body').replace('[code]', invitecode)
            send_mail(from_email, to_email, subject, body, from_name=_("Kevin from Gitcoin.co"))
            messages.success(request, _('Invite sent'))
        finally:
            translation.activate(cur_language)

        return redirect('/_administration/tdi/whitepaperaccessrequest/?processed=False')

    return TemplateResponse(request, 'process_accesscode_request.html', context)
Exemple #2
0
def notify_of_lowball_bounty(bounty):
    """Send an email to [email protected] with the lowball bounty info

    Args:
        bounty (dashboard.models.Bounty): The lowball bounty object

    """
    to_email = '*****@*****.**'
    cc_emails = '*****@*****.**'
    from_email = settings.CONTACT_EMAIL
    cur_language = translation.get_language()
    try:
        setup_lang(to_email)
        subject = _("Low Bounty Notification")
        body = \
            f"Bounty: {bounty}\n\n" \
            f"url: {bounty.url}\n\n" \
            f"Owner Name: {bounty.bounty_owner_name}\n\n" \
            f"Owner Email: {bounty.bounty_owner_email}\n\n" \
            f"Owner Address: {bounty.bounty_owner_address}\n\n" \
            f"Owner Profile: {bounty.bounty_owner_profile}"
        send_mail(from_email,
                  to_email,
                  subject,
                  body,
                  from_name=_("No Reply from Gitcoin.co"),
                  categories=['admin'],
                  cc_emails=cc_emails)
    finally:
        translation.activate(cur_language)
Exemple #3
0
def send_ptoken_redemption_accepted(profile, ptoken, redemption):
    from_email = settings.CONTACT_EMAIL
    to_email = profile.email
    if not to_email:
        if profile and profile.user:
            to_email = profile.user.email
    if not to_email:
        return

    cur_language = translation.get_language()

    try:
        setup_lang(to_email)
        html, text, subject = render_ptoken_redemption_accepted(
            ptoken, redemption)

        if not should_suppress_notification_email(to_email,
                                                  'personal_token_redemption'):
            send_mail(from_email,
                      to_email,
                      subject,
                      text,
                      html,
                      categories=['transactional',
                                  func_name()])
    finally:
        translation.activate(cur_language)
Exemple #4
0
def maybe_market_kudos_to_email(kudos_transfer):
    """Send an email for the specified Kudos.  The general flow of this function:

        - 1. Decide if we are sending it
        - 2. Generate subject
        - 3. Render email
        - 4. Send email
        - 5. Do translation

    Args:
        kudos_transfer (kudos.models.KudosTransfer): The Kudos Email object to be marketed.

    Returns:
        bool: Whether or not the email notification was sent successfully.

    """

    # 1. Decide if we are sending it
    if kudos_transfer.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK:
        logger.warning('Notifications are disabled.  Skipping email.')
        logger.debug(kudos_transfer.network)
        logger.debug(settings.ENABLE_NOTIFICATIONS_ON_NETWORK)
        return False

    if not kudos_transfer or not kudos_transfer.txid or not kudos_transfer.amount or not kudos_transfer.kudos_token_cloned_from:
        logger.warning('Some kudos information not found.  Skipping email.')
        return False

    # 2. Generate subject
    from_name = 'Someone' if not kudos_transfer.from_username else f'{kudos_transfer.from_username}'
    on_network = '' if kudos_transfer.network == 'mainnet' else f'({kudos_transfer.network})'
    subject = gettext(
        f"⚡️ {from_name} Sent You a {kudos_transfer.kudos_token_cloned_from.humanized_name} Kudos {on_network}"
    )

    logger.info(f'Emails to send to: {kudos_transfer.emails}')

    to_email = kudos_transfer.primary_email
    if to_email:
        cur_language = translation.get_language()
        try:
            setup_lang(to_email)
            # TODO:  Does the from_email field in the database mean nothing?  We just override it here.
            from_email = settings.CONTACT_EMAIL
            # 3. Render email
            html, text = render_new_kudos_email(to_email, kudos_transfer, True)

            # 4. Send email unless the email address has notifications disabled
            if not should_suppress_notification_email(to_email, 'kudos'):
                # TODO:  Should we be doing something with the response from SendGrid?
                #        Maybe we should store it somewhere.
                send_mail(from_email, to_email, subject, text, html)
        finally:
            # 5.  Do translation
            translation.activate(cur_language)

    return True
Exemple #5
0
def send_personal_token_created(profile, ptoken):
    from_email = settings.CONTACT_EMAIL
    to_email = profile.email
    cur_language = translation.get_language()

    try:
        setup_lang(to_email)
        html, text, subject = render_ptoken_created(ptoken)

        if not should_suppress_notification_email(to_email,
                                                  'personal_token_created'):
            send_mail(from_email,
                      to_email,
                      subject,
                      text,
                      html,
                      categories=['transactional',
                                  func_name()])
    finally:
        translation.activate(cur_language)
Exemple #6
0
 def test_setup_lang_no_user(self, mock_translation_activate):
     """Test the marketing mails setup_lang method."""
     setup_lang('*****@*****.**')
     assert mock_translation_activate.call_count == 0
Exemple #7
0
 def test_setup_lang(self, mock_translation_activate):
     """Test the marketing mails setup_lang method."""
     setup_lang(self.email)
     assert mock_translation_activate.call_count == 1
     mock_translation_activate.assert_called_once_with('en-us')