Exemple #1
0
def send_tip_2(request):

    if request.body != '':
        status = 'OK'
        message = 'Notification has been sent'
        params = json.loads(request.body)
        emails = []

        #basic validation
        if params['email']:
            emails.append(params['email'])
        gh_user = get_github_user(params['username'])
        if gh_user.get('email', False):
            emails.append(gh_user['email'])
        expires_date = timezone.now() + timezone.timedelta(
            seconds=params['expires_date'])

        #db mutations
        tip = Tip.objects.create(
            emails=emails,
            url=params['url'],
            tokenName=params['tokenName'],
            amount=params['amount'],
            comments=params['comments'],
            ip=get_ip(request),
            expires_date=expires_date,
            github_url=params['github_url'],
            from_name=params['from_name'],
            username=params['username'],
            network=params['network'],
            tokenAddress=params['tokenAddress'],
            txid=params['txid'],
        )

        #notifications
        did_post_to_github = maybe_market_tip_to_github(tip)
        maybe_market_tip_to_slack(tip, 'new_tip', tip.txid)
        tip_email(tip, set(emails), True)
        if len(emails) == 0 and not did_post_to_github:
            status = 'error'
            message = 'Uh oh! No email addresses found via Github API and could not post to github'

        #http response
        response = {
            'status': status,
            'message': message,
        }
        return JsonResponse(response)

    params = {
        'issueURL':
        request.GET.get('source'),
        'title':
        'Send Tip',
        'recommend_gas_price':
        recommend_min_gas_price_to_confirm_in_time(
            confirm_time_minutes_target),
    }

    return TemplateResponse(request, 'yge/send2.html', params)
Exemple #2
0
def resend_new_tip(request):
    from dashboard.models import Tip
    from marketing.mails import tip_email
    pk = request.POST.get('pk', request.GET.get('pk'))
    params = {
        'pk': pk,
    }

    if request.POST.get('pk'):
        email = request.POST.get('email')

        if not pk or not email:
            messages.error(request, 'Not sent.  Invalid args.')
            return redirect('/_administration')

        tip = Tip.objects.get(pk=pk)
        tip.emails = tip.emails + [email]
        tip_email(tip, [email], True)
        tip.save()

        messages.success(request, 'Resend sent')

        return redirect('/_administration')

    return TemplateResponse(request, 'resend_tip.html', params)
Exemple #3
0
 def handle(self, *args, **options):
     days = [1, 2]
     for day in days:
         tips = Tip.objects.send_success().filter(
             expires_date__lt=(timezone.now() + timezone.timedelta(days=(day+1))),
             expires_date__gte=(timezone.now() + timezone.timedelta(days=day)),
             receive_txid='',
             network='mainnet',
         ).all()
         print('day {} got {} tips'.format(day, tips.count()))
         for t in tips:
             tip_email(t, t.emails, False)
Exemple #4
0
 def handle(self, *args, **options):
     days = [1, 3, 14, 15, 13]
     for day in days:
         # TODO: In future, check blockchain to see if tip has been redeemed
         tips = Tip.objects.filter(
             expires_date__lt=(timezone.now() +
                               timezone.timedelta(days=(day + 1))),
             expires_date__gte=(timezone.now() +
                                timezone.timedelta(days=day)),
         ).all()
         print('day {} got {} tips'.format(day, tips.count()))
         for t in tips:
             tip_email(t, t.emails, False)
Exemple #5
0
def maybe_market_tip_to_email(tip, emails):
    """Send an email for the specified Tip.

    Args:
        tip (dashboard.models.Tip): The Tip to be marketed.
        emails (list of str): The list of emails to notify.

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

    """
    if tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK:
        return False

    tip_email(tip, set(emails), True)
    return True
Exemple #6
0
def maybe_market_tip_to_email(tip, emails):
    if tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK:
        return False

    tip_email(tip, set(emails), True)
    return True
Exemple #7
0
def send_tip_2(request):

    if request.body != '':
        status = 'OK'
        message = 'Notification has been sent'
        params = json.loads(request.body)
        emails = []

        #basic validation
        username = params['username']

        #get emails
        if params['email']:
            emails.append(params['email'])
        gh_user = get_github_user(username)
        user_full_name = gh_user['name']
        if gh_user.get('email', False):
            emails.append(gh_user['email'])
        gh_user_events = get_github_user(username, '/events/public')
        for event in gh_user_events:
            commits = event.get('payload', {}).get('commits', [])
            for commit in commits:
                email = commit.get('author', {}).get('email', None)
                #print(event['actor']['display_login'].lower() == username.lower())
                #print(commit['author']['name'].lower() == user_full_name.lower())
                #print('========')
                if email and \
                    event['actor']['display_login'].lower() == username.lower() and \
                    commit['author']['name'].lower() == user_full_name.lower() and \
                    'noreply.github.com' not in email and \
                    email not in emails:
                    emails.append(email)
        expires_date = timezone.now() + timezone.timedelta(
            seconds=params['expires_date'])

        #db mutations
        tip = Tip.objects.create(
            emails=emails,
            url=params['url'],
            tokenName=params['tokenName'],
            amount=params['amount'],
            comments_priv=params['comments_priv'],
            comments_public=params['comments_public'],
            ip=get_ip(request),
            expires_date=expires_date,
            github_url=params['github_url'],
            from_name=params['from_name'],
            from_email=params['from_email'],
            username=params['username'],
            network=params['network'],
            tokenAddress=params['tokenAddress'],
            txid=params['txid'],
        )

        #notifications
        did_post_to_github = maybe_market_tip_to_github(tip)
        maybe_market_tip_to_slack(tip, 'new_tip', tip.txid)
        tip_email(tip, set(emails), True)
        if len(emails) == 0:
            status = 'error'
            message = 'Uh oh! No email addresses for this user were found via Github API.  Youll have to let the tipee know manually about their tip.'

        #http response
        response = {
            'status': status,
            'message': message,
        }
        return JsonResponse(response)

    params = {
        'issueURL':
        request.GET.get('source'),
        'class':
        'send2',
        'title':
        'Send Tip',
        'recommend_gas_price':
        recommend_min_gas_price_to_confirm_in_time(
            confirm_time_minutes_target),
    }

    return TemplateResponse(request, 'yge/send2.html', params)