Esempio n. 1
0
    def post(self, request):

        file = request.POST.get('file')
        path = request.POST.get('path', '')

        db_file = File.objects.get(owner=request.user,
                                   filename=file,
                                   path=path)

        if db_file.hidden:
            if not check_vault_token(request.session.get('vault'),
                                     request.user):
                return HttpResponseRedirect(
                    reverse('mypage:main_page', kwargs={'path': ''}))

            file_path = os.path.join(
                request.user.user_profile.folder + '_vault', file)
            redirect = reverse('mypage:vault_page')
        else:
            file_path = os.path.join(
                os.path.join(request.user.user_profile.folder, path), file)
            redirect = reverse('mypage:main_page', kwargs={'path': path})

        if db_file.encrypted is False:

            new_path = encrypt_file(file_path, request.user)

            db_file.filename = os.path.basename(new_path)
            db_file.encrypted = True

            db_file.save()

            os.remove(file_path)

        return HttpResponseRedirect(redirect)
Esempio n. 2
0
    def post(self, request):

        path = request.POST.get('path')
        file = request.POST.get('file')

        if (check_vault_token(request.session.get('vault'), request.user)):
            file_obj = File.objects.get(owner=request.user,
                                        filename=file,
                                        path=path)

            if not file_obj.hidden:
                return HttpResponseRedirect(
                    reverse('mypage:main_page', kwargs={'path': path}))

            new_file_path = os.path.join(
                request.user.user_profile.folder,
                file_obj.filename,
            )

            file_path = os.path.join(
                request.user.user_profile.folder + '_vault',
                file_obj.filename,
            )

            shutil.copyfile(file_path, new_file_path)

            file_obj.path = ''
            file_obj.hidden = False

            file_obj.save()

            os.remove(file_path)

        return HttpResponseRedirect(reverse('mypage:vault_page'))
Esempio n. 3
0
    def post(self, request):

        file = request.POST.get('file')
        path = request.POST.get('path', '')

        if not file:
            return HttpResponseRedirect(
                reverse('mypage:main_page', kwargs={'path': path}))

        file_obj = File.objects.get(owner=request.user,
                                    filename=file,
                                    path=path)

        if file_obj.hidden:
            if not check_vault_token(request.session.get('vault'),
                                     request.user):
                return HttpResponseRedirect(
                    reverse('mypage:main_page', kwargs={'path': ''}))

            file_path = os.path.join(
                request.user.user_profile.folder + '_vault', file)
            redirect = reverse('mypage:vault_page')
        else:
            file_path = os.path.join(
                os.path.join(request.user.user_profile.folder, path), file)
            redirect = reverse('mypage:main_page', kwargs={'path': path})

        if file_obj:
            copy_file_obj = File()

            base_path, ext = os.path.splitext(file_path)
            copy_path = base_path + ' - Copy' + ext

            copy_file_obj.owner = request.user
            copy_file_obj.filename = os.path.splitext(
                file)[0] + ' - Copy' + ext
            copy_file_obj.path = file_obj.path
            copy_file_obj.file_type = file_obj.file_type
            copy_file_obj.size = file_obj.size
            copy_file_obj.hidden = file_obj.hidden

            if os.path.exists(copy_path):
                copy_path, i = find_good_name(copy_path)
                copy_file_obj.filename = ''.join([
                    os.path.splitext(copy_file_obj.filename)[0],
                    ' ({})'.format(i),
                    ext,
                ])

            shutil.copyfile(file_path, copy_path)

            copy_file_obj.save()

        return HttpResponseRedirect(redirect)
Esempio n. 4
0
    def get(self, request):

        if not check_vault_token(request.session.get('vault'), request.user):
            request.session['vault'] = None

            return HttpResponseRedirect(
                reverse('mypage:main_page', kwargs={'path': ''}))

        vault_files = File.objects.filter(
            owner=request.user,
            hidden=True,
        ).order_by('-filename')

        context = {
            'vault_files': vault_files,
            'path': '',
            'default_profile_pic_url': DEFAULT_PROFILE_PIC_URL,
        }

        return render(request, 'page/vault_page.html', context=context)
Esempio n. 5
0
    def get(self, request, path=''):

        upload_form = UploadFileForm()

        files = File.objects.filter(
            owner=request.user,
            path=path,
            hidden=False,
        ).order_by('-is_directory', '-filename')

        directories = files.filter(is_directory=True)

        shared_by_me = request.user.files.filter(shared=True)

        for file in shared_by_me:
            for i in file.instances.all():
                print(i.shared_with)

        shared_with_me = request.user.shared_with.all()

        # print('received:{}'.format(request.session.get('vault')))
        # print()

        vault_access = True
        if not check_vault_token(request.session.get('vault'), request.user):
            vault_access = False
            request.session['vault'] = None

        context = {
            'path': path,
            'files': files,
            'directories': directories,
            'upload_form': upload_form,
            'shared_by_me': shared_by_me,
            'shared_with_me': shared_with_me,
            'vault_access': vault_access,
            'default_profile_pic_url': DEFAULT_PROFILE_PIC_URL,
        }

        return render(request, 'page/my_page.html', context=context)
Esempio n. 6
0
    def post(self, request):

        file = request.POST.get('file')
        path = request.POST.get('path', '')

        if file:

            db_file = File.objects.get(owner=request.user,
                                       filename=file,
                                       path=path)

            if db_file.hidden:

                if not check_vault_token(request.session.get('vault'),
                                         request.user):
                    return HttpResponseRedirect(
                        reverse('mypage:main_page', kwargs={'path': ''}))

                os.remove(
                    os.path.join(
                        request.user.user_profile.folder + '_vault',
                        file,
                    ))

                db_file.delete()

                return HttpResponseRedirect(reverse('mypage:vault_page'))

            # print(db_file)
            db_file.delete()

            # print(os.path.join(os.path.join(request.user.user_profile.folder, path), file))
            os.remove(
                os.path.join(
                    os.path.join(request.user.user_profile.folder, path),
                    file))
        # return HttpResponse('<script>history.back();</script>')

        return HttpResponseRedirect(
            reverse('mypage:main_page', kwargs={'path': path}))
Esempio n. 7
0
    def post(self, request):

        file = request.POST.get('file')
        path = request.POST.get('path', '')

        db_file = File.objects.get(owner=request.user,
                                   filename=file,
                                   path=path)

        if db_file.hidden:

            if not check_vault_token(request.session.get('vault'),
                                     request.user):
                return HttpResponseRedirect(
                    reverse('mypage:main_page', kwargs={'path': ''}))

            file_path = os.path.join(
                request.user.user_profile.folder + '_vault',
                file,
            )

            redirect_rev = reverse('mypage:vault_page')
        else:

            file_path = os.path.join(
                os.path.join(request.user.user_profile.folder, path), file)
            redirect_rev = reverse('mypage:main_page', kwargs={'path': path})

        if os.path.exists(file_path):
            with open(file_path, 'rb') as fh:
                response = HttpResponse(
                    fh.read(), content_type="application/vnd.ms-excel")
                response[
                    'Content-Disposition'] = 'inline; filename=' + os.path.basename(
                        file_path)
                return response

        return HttpResponseRedirect(redirect_rev)