Esempio n. 1
0
def deleteFile(fileId, filename):

    userId = RetrieveSessionDetails('userId')
    currentFolderId = RetrieveSessionDetails('currentFolderId')

    parentFolderId, parentfolderName = BusinessLayer.getParentFolderForFile(
        fileId, userId)
    print("kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk: ", parentFolderId)
    print("llllllllllllllllllllllllllllllllllllllllll: ", parentfolderName)

    flag = BusinessLayer.RemoveExisitngFile(userId, currentFolderId, fileId,
                                            filename)

    if flag == True:

        try:
            path = BusinessLayer.getPathForFolder(userId, parentFolderId)
            target = os.path.join(APP_STORAGE_PATH, path)
            destination = "/".join([target, filename])
            os.remove(destination)
            AddToSession('TotalSize', BusinessLayer.getTotalSize(userId))

        except OSError:
            pass

    return redirect(url_for('index', folderId=currentFolderId))
Esempio n. 2
0
File: app.py Progetto: pnjha/DropBox
def deleteFile(fileId,filename):
    userId = RetrieveSessionDetails('userId')
    currentFolderId = RetrieveSessionDetails('currentFolderId')
    flag = BusinessLayer.RemoveExisitngFile(userId,currentFolderId,fileId,filename)    

    AddToSession('TotalSize',BusinessLayer.getTotalSize(userId))

    return redirect(url_for('index',folderId = currentFolderId))
Esempio n. 3
0
def deleteFolder(folderId, foldername):
    userId = RetrieveSessionDetails('userId')
    currentFolderId = RetrieveSessionDetails('currentFolderId')
    path = BusinessLayer.getPathForFolder(userId, folderId)
    flag = BusinessLayer.RemoveExisitngFolder(userId, currentFolderId,
                                              folderId, foldername)

    if flag == 1:

        target = os.path.join(APP_STORAGE_PATH, path)

        print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa target: ", target)

        shutil.rmtree(target)
        AddToSession('TotalSize', BusinessLayer.getTotalSize(userId))

    AddToSession('TotalSize', BusinessLayer.getTotalSize(userId))

    return redirect(url_for('index', folderId=currentFolderId))
Esempio n. 4
0
def validate():
    print("-------Inside Validate-------")
    error = None
    # if request.method == 'GET':
    #     print("-------Inside Validate method GET-------")
    #     username = request.form.get('username')
    #     password = request.form.get('password')
    #     print("Username is: ", username, " and Password is: ",password)
    if request.method == 'POST':
        print("-------Inside Validate method POST-------")
        username = request.form.get('username')
        password = request.form.get('password')
        # print("Username is: ", username, " and Password is: ",password)

        UserData = BusinessLayer.ValidateUser(username, password)

        if ("Invalid Login Attempt" in UserData.values()):

            error = "Please check username or password !"
            return render_template("login.html", error=error)

        print("  #### ", UserData['UserDetails'].currentFolderId)

        AddToSession('userId', UserData['UserDetails'].userid)
        AddToSession('userName', UserData['UserDetails'].userName)
        AddToSession('currentFolderId',
                     UserData['UserDetails'].currentFolderId)
        AddToSession('homeFolderId', UserData['UserDetails'].HomeFolderId)
        AddToSession(
            'TotalSize',
            BusinessLayer.getTotalSize(UserData['UserDetails'].userid))

        foldername = UserData['UserDetails'].currentFolderName[:-1]

        AddToSession('currentFolderName', foldername)

        if 'InvalidLogin' in UserData:
            if UserData['InvalidLogin'] == 'Invalid Login Attempt':
                return render_template("login.html", error=error)
        else:
            print("---------User Validated------")
            userId = UserData['UserDetails'].userid
            print("Userid is: ", userId)

            homeFolder = BusinessLayer.getHomeFolderId(userId)
            print("HomeFolderId is: ", homeFolder.folderid)

            return redirect(url_for('index', folderId=homeFolder.folderid))
    else:
        return render_template('login.html')
Esempio n. 5
0
def upload():

    if request.method == "POST":

        userId = RetrieveSessionDetails('userId')
        currentFolderId = RetrieveSessionDetails('currentFolderId')

        print("userId: ", userId)
        print("currentFolderId: ", currentFolderId)

        path = BusinessLayer.getPathForFolder(userId, currentFolderId)

        print("path: ", path)
        target = os.path.join(APP_STORAGE_PATH, path)
        print("Target path: ", target)

        if not os.path.isdir(target):
            os.mkdir(target)

        for upload in request.files.getlist("file"):

            filename = upload.filename
            destination = "/".join([target, filename])
            upload.save(destination)

            file_size = os.stat(destination).st_size
            print("file size: ", file_size)

            fileObj = FileClass()
            fileObj.setFileDetails(46, filename, 0, file_size, userId,
                                   currentFolderId)

            fileObj = BusinessLayer.createFile(fileObj, userId,
                                               currentFolderId)
            print(fileObj)

        UserData = BusinessLayer.getFolderContents(userId, currentFolderId)

        AddToSession('TotalSize', BusinessLayer.getTotalSize(userId))

        return redirect(url_for('index', folderId=currentFolderId))

    else:
        return render_template("404.html")