<filename>views.py<gh_stars>1-10
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from .models import *
from cryptography.fernet import Fernet
from django.utils.crypto import get_random_string
from .forms import *
# Create your views here.

def index(request):
    return render(request, "pasteindex.html")


def add(request):
    if request.method == "POST":
        MyForm = PasteForm(request.POST)
        if MyForm.is_valid():
            Text = MyForm.cleaned_data['Text']
            Burn = MyForm.cleaned_data['Burn']
            Key = get_random_string(length=5)
            try:
                test = Paste.objects.get(Paste_Key=Key)
                Key = get_random_string(length=5)
            except Paste.DoesNotExist:
                owo = Paste(Paste_Text=Text, Paste_Key=Key, Paste_Burn=Burn)
                owo.save()
                return HttpResponse("/pastebin/"+Key)
    else:
        form = PasteForm()
        return render(request, "pasteadd.html", {"form":form})

def view(request, url_id):
    try:
        OwO = Paste.objects.get(Paste_Key=url_id)
    except Paste.DoesNotExist:
        return HttpResponse("404")
    Text = OwO.Paste_Text
    Burn = OwO.Paste_Burn
    if Burn == True:
        OwO.delete()
    return render(request, "pasteout.html", {'Text':Text, 'Burn':Burn})

def addowo(request):
    if request.method == "POST":
        MyForm = PasteForm(request.POST)
        if MyForm.is_valid():
            Text = MyForm.cleaned_data['Text']
            Burn = MyForm.cleaned_data['Burn']
            Key = get_random_string(length=5)
            try:
                test = EncryptPaste.objects.get(Paste_Key=Key)
                Key = get_random_string(length=5)
            except EncryptPaste.DoesNotExist:
                OwOKey = Fernet.generate_key()
                F = Fernet(OwOKey)
                Text = F.encrypt(bytes(Text, 'utf-8'))
                owo = EncryptPaste(Paste_Text=Text.decode(), Paste_Burn=Burn, Paste_Key=Key)
                owo.save()
                return render(request, "pasteoutowo.html", {'Key':Key, "OwOKey":OwOKey.decode()})
                
    else:
        form = PasteForm(request.POST)
        return render(request, "pasteaddowo.html", {'form':form})

def viewowo(request, url_id):
    if request.method == "POST":
        MyForm = EncryptForm(request.POST)
        if MyForm.is_valid():
            Key = MyForm.cleaned_data["Key"]
            Key = Key.encode()
            try:
                owo = EncryptPaste.objects.get(Paste_Key=url_id)
            except EncryptPaste.DoesNotExist:
                return HttpResponse("404")
            Text = owo.Paste_Text
            try:
                F = Fernet(Key)
                out = F.decrypt(Text.encode())
            except:
                return HttpResponse("error")
            Burn = owo.Paste_Burn
            if owo.Paste_Burn == True:
                owo.delete()
            return render(request, 'outowo.html', {"Text":out.decode(), "Burn":Burn})
    else:
        try:
            owo = EncryptPaste.objects.get(Paste_Key=url_id)
        except EncryptPaste.DoesNotExist:
            return HttpResponse("404")
        form = EncryptForm()
        return render(request, "checkowo.html", {'form':form})

<filename>views.py<gh_stars>1-10
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from .models import *
from cryptography.fernet import Fernet
from django.utils.crypto import get_random_string
from .forms import *
# Create your views here.

def index(request):
    return render(request, "pasteindex.html")


def add(request):
    if request.method == "POST":
        MyForm = PasteForm(request.POST)
        if MyForm.is_valid():
            Text = MyForm.cleaned_data['Text']
            Burn = MyForm.cleaned_data['Burn']
            Key = get_random_string(length=5)
            try:
                test = Paste.objects.get(Paste_Key=Key)
                Key = get_random_string(length=5)
            except Paste.DoesNotExist:
                owo = Paste(Paste_Text=Text, Paste_Key=Key, Paste_Burn=Burn)
                owo.save()
                return HttpResponse("/pastebin/"+Key)
    else:
        form = PasteForm()
        return render(request, "pasteadd.html", {"form":form})

def view(request, url_id):
    try:
        OwO = Paste.objects.get(Paste_Key=url_id)
    except Paste.DoesNotExist:
        return HttpResponse("404")
    Text = OwO.Paste_Text
    Burn = OwO.Paste_Burn
    if Burn == True:
        OwO.delete()
    return render(request, "pasteout.html", {'Text':Text, 'Burn':Burn})

def addowo(request):
    if request.method == "POST":
        MyForm = PasteForm(request.POST)
        if MyForm.is_valid():
            Text = MyForm.cleaned_data['Text']
            Burn = MyForm.cleaned_data['Burn']
            Key = get_random_string(length=5)
            try:
                test = EncryptPaste.objects.get(Paste_Key=Key)
                Key = get_random_string(length=5)
            except EncryptPaste.DoesNotExist:
                OwOKey = Fernet.generate_key()
                F = Fernet(OwOKey)
                Text = F.encrypt(bytes(Text, 'utf-8'))
                owo = EncryptPaste(Paste_Text=Text.decode(), Paste_Burn=Burn, Paste_Key=Key)
                owo.save()
                return render(request, "pasteoutowo.html", {'Key':Key, "OwOKey":OwOKey.decode()})
                
    else:
        form = PasteForm(request.POST)
        return render(request, "pasteaddowo.html", {'form':form})

def viewowo(request, url_id):
    if request.method == "POST":
        MyForm = EncryptForm(request.POST)
        if MyForm.is_valid():
            Key = MyForm.cleaned_data["Key"]
            Key = Key.encode()
            try:
                owo = EncryptPaste.objects.get(Paste_Key=url_id)
            except EncryptPaste.DoesNotExist:
                return HttpResponse("404")
            Text = owo.Paste_Text
            try:
                F = Fernet(Key)
                out = F.decrypt(Text.encode())
            except:
                return HttpResponse("error")
            Burn = owo.Paste_Burn
            if owo.Paste_Burn == True:
                owo.delete()
            return render(request, 'outowo.html', {"Text":out.decode(), "Burn":Burn})
    else:
        try:
            owo = EncryptPaste.objects.get(Paste_Key=url_id)
        except EncryptPaste.DoesNotExist:
            return HttpResponse("404")
        form = EncryptForm()
        return render(request, "checkowo.html", {'form':form})

# Create your views here.