Exemplo n.º 1
0
def spell():
    form = SpellForm()
    #if login_user(user) == False:
        #flash('Please Log In', 'danger')
        #return redirect(url_for('login'))
    curr = current_user.username
    if form.validate_on_submit(): 
        flash('Submitted Successfully', 'success')
        inputtext = form.inputtext.data 
        with open('userinput.txt', 'w') as f:
            f.write(form.inputtext.data)
            f.close()

        #print(inputtext)

        spellout = subprocess.run(['./a.out', 'userinput.txt', 'wordlist.txt'], check=True, stdout=subprocess.PIPE, universal_newlines=True) #use if using python3.6
        #spellout = subprocess.run(['./a.out', 'userinput.txt', 'wordlist.txt'], capture_output=True, text=True) # stderr=subprocess.DEVNULL

        with open('mispelled.txt', 'w') as g:
            g.write(spellout.stdout)
            g.close()
        with open('mispelled.txt', 'r') as g:
            mispelled = g.read().replace('\n', ', ').strip().strip(',')
            g.close()
        print(inputtext)
        print(mispelled)
        newlog = spellTable(username=curr, querytext=inputtext, queryresults=mispelled)
        db.session.add(newlog)
        db.session.commit()
        #spellout2 = spellout.stdout
        #print(spellout.stdout)
    
        return render_template('spell_check.html', title = 'Spell Checker', pagename = 'Spell Check Page', textout = inputtext, misspelled = mispelled, form = form)
    
    return render_template('spell_check.html', title = 'Spell Checker', pagename = 'Spell Check Page', form = form)
Exemplo n.º 2
0
def add_spell(request):
    form = SpellForm()
    if request.method == "POST":
        spell = SpellForm(data=request.POST, files=request.FILES)
        if spell.is_valid():
            spell.save()
            return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.spells'))
        else:
            form = spell
    return render_to_response('cpanel/add_spell.html', {'form': form, 'module': 'spells'}, context_instance=RequestContext(request))
Exemplo n.º 3
0
def edit_spell(request, id):
    spell = get_object_or_404(Spell, pk=id)
    if request.method == "POST":
        form = SpellForm(data = request.POST, instance = spell, files=request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.spells'))
    else:
        form = SpellForm(instance=spell)
    return render_to_response('cpanel/edit_spell.html', {'form':form, 'module': 'spells'}, context_instance=RequestContext(request))
Exemplo n.º 4
0
def spell_check():
    textout = None
    misspelled = None
    form = SpellForm()
    if form.validate_on_submit():
        textout = request.form['inputtext']
        filename = urandom(32).hex()
        f = open(filename, 'w')
        f.write(textout)
        f.close()
        stdout, stderr = Popen(['./a.out', filename, 'wordlist.txt'],
            stdout=PIPE, stderr=STDOUT).communicate()
        misspelled = stdout.decode().replace('\n',',')
        p = Popen(['rm', filename], stdout=PIPE, stderr=STDOUT)

    return render_template('spell_check.html', \
            form=form, textout=textout,misspelled=misspelled)
Exemplo n.º 5
0
def edit_spell(request, id):

    spell = get_object_or_404(Spell, pk=id)
    if request.method == "POST":
        form = SpellForm(data = request.POST, instance = spell)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.spells'))
    else:
        form = SpellForm(instance=spell)
    return render_to_response('cpanel/edit_spell.html', {'form':form, 'module': 'spells'}, context_instance=RequestContext(request))
Exemplo n.º 6
0
def add_spell(request):
    form = SpellForm()
    if request.method == "POST":
        spell = SpellForm(data = request.POST)
        if spell.is_valid():
            spell.save()
            return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.spells'))
        else:
            form = spell
    return render_to_response('cpanel/add_spell.html', {'form': form, 'module': 'spells'}, context_instance=RequestContext(request))