Esempio n. 1
0
def acceptRequest(request, shareid):
    currentUser = get_object_or_404(CustomUser, user=request.user)
    shareable = get_object_or_404(SharedSecretFile, id=shareid)
    if currentUser != shareable.destiny_user:
        HttpResponse("This is not your file")
    else:
        file = SecretFile()
        file.owner = currentUser
        file.name = shareable.name
        file.key = shareable.key
        file.iv = shareable.iv
        file.ct = shareable.ct
        uploadedfile = uploadToDrive(request.user, file)
        file.iddrive = uploadedfile["id"]
        file.lastmodified = uploadedfile["modifiedDate"]
        file.ct = str()
        file.save()
        shareable.delete()
        return HttpResponse("File has been saved to your drive")
Esempio n. 2
0
def upload(request):
    """
    Takes an authenticated user and saves
    the given file
    """
    owner = get_object_or_404(CustomUser, user=request.user)
    if request.method == "POST":
        form = FileUpload(request.POST)
        if form.is_valid():
            file = form.save(commit=False)
            file.owner = owner
            uploadedfile = uploadToDrive(request.user, file)
            file.iddrive = uploadedfile["id"]
            file.lastmodified = uploadedfile["modifiedDate"]
            file.ct = str()  # erase file content
            file.save()
            return redirect("sirs_files:upload")
        else:
            return render(request, "sirs_files/upload.html", {"form": form})
    else:
        form = FileUpload(initial={"pubKey": owner.publicKey})
        return render(request, "sirs_files/upload.html", {"form": form})