Exemple #1
0
def create(request):
    if request.method == 'POST':
        form = secretsforms.createBlackmailForm(request.POST)
        if form.is_valid():
            #If the user is not logged in, need to have them do so.
            if not isLoggedIn(request):
                #CHECK: Should this be a return statement instead?
                redirect('/secrets/signin/')

            #must get target and owner before calling createBlackmail. 
                #Owner should be known if the user creating the blackmail is
                #logged in. If the user is not logged in, they would have been
                #redirected to the signin page.

                #CHECK: Should the target info be a valid user or just an
                #email?
            createBlackmail(request, target, owner, 
                            form.cleaned_data['picture'],
                            form.cleaned_data['deadline'],
                            form.cleaned_data['demands'])
            #if the blackmail was created, should redirect to details page with
            #blackmail
                # TODO ^ : Search database for bm_id; if found, redirect
                    #CHECK: Can an owner have multiple ACTIVE blackmails out on
                    #the same target?
                    # If so,
                        #need to create a method to get the ID of the currently
                        #selected record. (In this case, the current record would
                        #be the newly created record; perhaps the createBlackmail
                        #function should return the new record's ID).
                    # If not,
                        #need to make sure the user knows they are already
                        #blackmailing that target. Redirect to Edit page?
            return redirect('/secrets/create.html/(?P<bm_id>\d+)/')
        else:
            c = {}
            c.update(csrf(request))
            c['formhaserrors'] = True
            c['form'] = form
            return render_to_response('secrets/create.html', c)
    else:
        form = secretsforms.createBlackmailForm()
        c = {}
        c.update(csrf(request))
        c['form'] = form
        return render_to_response('secrets/create.html', c)

    return HttpResponse("create bm page")
Exemple #2
0
def create(request):
    # outputDict contains everything that will be passed to the template
    outputDict = {}

    # If the user is not logged in, need to have them do so.
    if not isLoggedIn(request):
        return redirect("/secrets/signin/")
    else:
        curUser = request.session.get("useremail", "")
        outputDict["curuser"] = request.session.get("username", "")

    if request.method == "POST":
        randpw = ""
        form = secretsforms.createBlackmailForm(request.POST, request.FILES)
        if form.is_valid():
            # Get target and owner objects before calling createBlackmail.
            o = Person.objects.get(email=request.session["useremail"])
            tEMail = form.cleaned_data["target"]
            # See if the current target is found in the database.
            try:
                t = Person.objects.get(email=tEMail)
                randpw = "your current password"
            except Person.DoesNotExist:
                randpw = str(random.randint(100000, 1000000))
                try:
                    tname = form.cleaned_data["tname"]
                    if len(tname) is 0:
                        tname = "TARGET"
                except:
                    tname = "TARGET"
                createUserAccount(request, tname, tEMail, randpw, randpw, True)
                t = Person.objects.get(email=tEMail)

            # An owner cannot have multiple ACTIVE blackmails out on the same
            # target. If attempted, redirect to Edit page.
            try:
                blackmail = Blackmail.objects.get(target__id=t.pk, owner__id=o.pk)
                if blackmail:
                    return redirect("/secrets/edit/%s/" % blackmail.pk)
            except Blackmail.DoesNotExist:
                createBlackmail(request, t, o, request.FILES["picture"], form.cleaned_data["deadline"])

                # Get the newly created blackmail object
                blackmail = Blackmail.objects.get(target__id=t.pk, owner__id=o.pk)

                # get demands to go with the blackmail
                createNewTerm(blackmail, form.cleaned_data["term1"])

                strterm2 = form.cleaned_data["term2"]
                if strterm2:
                    createNewTerm(blackmail, strterm2)
                strterm3 = form.cleaned_data["term3"]
                if strterm3:
                    createNewTerm(blackmail, strterm3)

            # send target an email
            sendTargetEmail(tEMail, blackmail.pk, randpw)

            # Redirect to details page so user can see newly created blackmail data.
            return redirect("/secrets/details/%s/" % blackmail.pk)

        else:
            outputDict.update(csrf(request))
            outputDict["formhaserrors"] = True
            outputDict["form"] = form
            return render_to_response("secrets/create.html", outputDict)

    else:
        form = secretsforms.createBlackmailForm()
        outputDict.update(csrf(request))
        outputDict["form"] = form
        return render_to_response("secrets/create.html", outputDict)

    return HttpResponse("create bm page")
Exemple #3
0
def create(request):
    #outputDict contains everything that will be passed to the template
    outputDict = {}
    
    #If the user is not logged in, need to have them do so.
    if not isLoggedIn(request):
        return redirect('/secrets/signin/')
    else:
        curUser = request.session.get('useremail','')
        outputDict['curuser'] = request.session.get('username','')
        
    if request.method == 'POST':
        randpw = ''
        form = secretsforms.createBlackmailForm(request.POST, request.FILES)
        if form.is_valid():
            #Get target and owner objects before calling createBlackmail.
            o = Person.objects.get(email=request.session['useremail'])
            tEMail = form.cleaned_data['target']
            #See if the current target is found in the database.
            try:
                t = Person.objects.get(email=tEMail)
                randpw = 'your current password'
            except Person.DoesNotExist:
                randpw = str(random.randint(100000, 1000000))
                createUserAccount(request, 'TARGET', tEMail, randpw, randpw, True)
                t = Person.objects.get(email=tEMail)

            #An owner cannot have multiple ACTIVE blackmails out on the same
            #target. If attempted, notify user they are already blackmailing that
            #target, then redirect to Edit page.
            try:
                blackmail = Blackmail.objects.get(target__id=t.pk, owner__id=o.pk)
                if blackmail:
                     return redirect('/secrets/edit/%s/' %blackmail.pk)
            except Blackmail.DoesNotExist:
                createBlackmail(request, t, o, 
                                                 request.FILES['picture'],
                                                 form.cleaned_data['deadline'])
                
                #Get the newly created blackmail object
                blackmail = Blackmail.objects.get(target__id=t.pk, owner__id=o.pk)
                
                #get demands to go with the blackmail
                createNewTerm(blackmail, form.cleaned_data['term1'])
                
                strterm2 = form.cleaned_data['term2']
                if strterm2:
                    createNewTerm(blackmail, strterm2)
                strterm3 = form.cleaned_data['term3']
                if strterm3:
                    createNewTerm(blackmail, strterm3)

            #send target an email
            sendTargetEmail(tEMail, blackmail.pk, randpw)

            #Redirect to details page so user can see newly created blackmail data.
            return redirect('/secrets/details/%s/' %blackmail.pk)

        else:
            outputDict.update(csrf(request))
            outputDict['formhaserrors'] = True
            outputDict['form'] = form
            return render_to_response('secrets/create.html', outputDict)

    else:
        form = secretsforms.createBlackmailForm()
        outputDict.update(csrf(request))
        outputDict['form'] = form
        return render_to_response('secrets/create.html', outputDict)

    return HttpResponse("create bm page")