Ejemplo n.º 1
0
def auto_ticket(request):
    #you thought you were going to break things by not having an e-mail? ha!
    if not request.user.email:
        return redirect('account/email')
    if request.method == 'POST':
        game = AutoCode()
        #!!!
        #let's talk about security sometime...(...later)(...never)
        up = UserProfile.objects.get(user = request.user)
        if 'ticket_random' in request.POST:
            if up.ticket_decrement(1):
                if not game.code_rand(request.user.email):
#this wouldn't be necessary if I didn't do these 'function evaluates t/f' things
                    up.ticket_increment(1) 
                    return HttpResponse('Oops<br>You have been refunded.')
            else:
                return HttpResponse('not enough tickets: '+str(up.ticket_count))
        elif 'ticket_selection' in request.POST:
            gsf = GameSelectForm(request.POST)
            if gsf.is_valid():
                if up.ticket_decrement(2):
                    if not game.code_select(request.user.email, gsf.cleaned_data['gameselect'].id):
                        up.ticket_increment(2)
                        return HttpResponse('Oops<br>You have been refunded.')
                else:
                    return HttpResponse('not enough tickets: '+str(up.ticket_count))
            else:
                return HttpResponse('invalid choice')
            
#TODO
        print game
        print str(game.code)
        attach_code = game
        subject = 'Here is your requested code!'
        if attach_code:
            url_get = game.get_url_get()
            url_return = game.get_url_return()
        #hahaha, oh wow what is this mess
            message = '<br>' + 'Here is a code for ' + str(game.game) +'.<br> To redeem it, go to '+url_get+'<br>If you would like to return it to us, go to '+url_return
        else:
            message = '<br>Unfortunately, we are out of codes for '+str(game.game) + '.' 
        print message
        donation_mail = mailbot.pack_MIME(message, request.user.email, subject)
        mailbot.send_mail(donation_mail, request.user.email)
        
   
        diagnostic = str(game.game.id)
        return HttpResponse('Check your email for your gift of '+str(game.game)+ '<br>'+diagnostic)
    return HttpResponse('huh?')
Ejemplo n.º 2
0
def auto_donate(request):
    #you thought you were going to break things by not having an e-mail? ha!
    if not request.user.email:
        return redirect('account/email')
    if request.method == 'POST':

#TODO: game selection not necessarily hardcoded
        game_id = DONATION_GIVEAWAY_ID 
#TODO: donation message based on real donation info
#I don't actually have systems for that. This isn't a real marathon site!
        donation = 'Thank you for your donation of ' + str(random.randint(2,100)) + ' ' + random.choice(['US Dollars', 'Bahraini Dinars', 'Icelandic Krona', 'Pakistani Rupees', 'Qatari Rial','Tanzanian Shillings','South Korean Won','Colombian Pesos','Estonian Kroon']) +'.'
        game = AutoCode()
        print game
        attach_code = game.code_select(request.user.email, game_id)
        subject = 'Thank you for "donating"'
        if attach_code:
            url_get = game.get_url_get()
            url_return = game.get_url_return()
        #hahaha, oh wow what is this mess
            message = donation + '<br>' + 'Here is a code for ' + str(game.game) +'.<br> To redeem it, go to '+url_get+'<br>If you would like to return it to us, go to '+url_return + '<br>This link will expire in 7 days, so don\'t forget to redeem it!'
        else:
            message = donation + '<br>Unfortunately, we are out of codes for '+str(game.game) + '.' 
        print message
        donation_mail = mailbot.pack_MIME(message, request.user.email, subject)
        mailbot.send_mail(donation_mail, request.user.email)
        
        update_ticket = UserProfile.objects.get(user = request.user)
        update_ticket.ticket_increment(1)
        if update_ticket.donation_update():
            print 'yes'
        context = {
            'donation': donation,
            'game' : game.game,
            
        }
        return render(request, 'dispenser/auto_donate.html', context)
    else:
        return redirect('/dispenser/auto')