Esempio 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?')