Exemplo n.º 1
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))
Exemplo n.º 2
0
Arquivo: app.py Projeto: pnjha/DropBox
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")            
Exemplo n.º 3
0
Arquivo: app.py Projeto: pnjha/DropBox
def permission(fileId,perms):

    userId = RetrieveSessionDetails('userId')
    currentFolderId = RetrieveSessionDetails("currentFolderId")
    isPermissionChanged = BusinessLayer.changePermission(userId,fileId,perms,currentFolderId)

    if isPermissionChanged == False :
            return render_template("404.html") 

    folderId = RetrieveSessionDetails('currentFolderId')

    return redirect(url_for('index',folderId = folderId))            
Exemplo n.º 4
0
Arquivo: app.py Projeto: pnjha/DropBox
def index(folderId):

    userId = RetrieveSessionDetails('userId')
    AddToSession('currentFolderId',folderId)
    foldername = BusinessLayer.getPathForFolder(userId,folderId)
    foldername = foldername[:-1]
    AddToSession('currentFolderName',foldername)
    #keyToAdd = 'PFDEL_'+foldername
    #AddToSession('directory_home',foldername)

    UserData = BusinessLayer.getFolderContents(userId, folderId)

    userclassInstance = UserClass()
    userclassInstance.setUserDetails(RetrieveSessionDetails('userId'),RetrieveSessionDetails('userName'),"passwd","name","email","phone")
    userclassInstance.setCurrentFolderId(RetrieveSessionDetails('currentFolderId'))
    userclassInstance.setCurrentFolderName(RetrieveSessionDetails('currentFolderName'))
    userclassInstance.setHomeFolderId(RetrieveSessionDetails('homeFolderId'))

    UserData['TotalSize'] = RetrieveSessionDetails('TotalSize')
    UserData['UserDetails'] = userclassInstance
    return render_template('index.html', **UserData)
Exemplo n.º 5
0
def openfile(fileId, fileName):

    userId = RetrieveSessionDetails('userId')

    parentFolderId, parentfolderName = BusinessLayer.getParentFolderForFile(
        fileId, userId)

    print("///////////////////////////////////////", parentFolderId,
          parentfolderName)

    path = BusinessLayer.getPathForFolder(userId, parentFolderId)
    target = os.path.join(APP_STORAGE_PATH, path)

    mime = MimeTypes()
    url = urllib.request.pathname2url(target)
    mime_type = mime.guess_type(url)
    print(mime_type)

    return send_from_directory(directory=target,
                               filename=fileName,
                               mimetype=mime_type[0])
Exemplo n.º 6
0
def navigate_to_user(user_hash):
    bLayerObj = bl.BusinessLayer()
    user_list = bLayerObj.getAllUserHashDistinct()

    print("user_list: ", user_list)

    # user_list = ['068fd0571f7cc527d4983d35f0d908d9', 'fde62956f023ab40685ecceee22c402e', 'b50f1867e01b21d3134b0097ecb7990d',
    # '73803249c6667c5af2d51c0dedfae487', 'e251a758734abbefe63347192e64ed9f', 'a269f1b41ae5073302d70baac6137ae2',
    # '34237272481aa6a02ea94799695a6982', '67d97bd65bfff6f9274ef52034fa0e19', '93e2f4935402da5361fcaeb636fc6cd2']

    return render_template("index.html",
                           user_hash=user_hash,
                           user_list=user_list)
Exemplo n.º 7
0
def moveFile(fileId, fileName):
    print("File id to move is: ", fileId, " and filename to move is: ",
          fileName)
    currentFolderId = RetrieveSessionDetails('currentFolderId')
    userId = RetrieveSessionDetails('userId')
    if 'newParentFolderId' in session:
        newParentFolderId = session['newParentFolderId']
        if BusinessLayer.CheckFilePresent(fileName, newParentFolderId,
                                          userId) == True:
            print(
                "File cannot be moved at destination as a file with same name already present at destination...."
            )
            session.pop('newParentFolderId', None)
            return redirect(url_for('index', folderId=currentFolderId))

        if BusinessLayer.setNewParentFolderForFile(fileId, userId,
                                                   newParentFolderId) == False:
            print("---Unable to update new Parent folder of file in DB")
            session.pop('newParentFolderId', None)
            return redirect(url_for('index', folderId=currentFolderId))

        srcPath = APP_STORAGE_PATH
        srcPath += BusinessLayer.getPathForFolder(userId, currentFolderId)
        srcPath += fileName
        print("-------File src path is: ", srcPath)
        destPath = APP_STORAGE_PATH
        destPath += BusinessLayer.getPathForFolder(userId, newParentFolderId)
        destPath += fileName
        print("------Destination path is: ", destPath)
        try:
            os.rename(srcPath, destPath)
            session.pop('newParentFolderId', None)
            print("----OH YEAH!! File successfully moved----")
        except OSError:
            print("-------OH NO!!! Unable to move file---------")
    else:
        print("Key not present in session")

    return redirect(url_for('index', folderId=currentFolderId))
Exemplo n.º 8
0
def registerUser():

    error = None

    if request.method == 'POST':
        email = request.form['email']
        pswd = request.form['psw']
        repswd = request.form['repswd']
        userName = request.form['username']
        name = request.form['name']

        phone = "9878989890"

        if (pswd != repswd):
            error = "Passwords do not match"
            return render_template('login.html', error=error)

        userexist = BusinessLayer.isUserExist(userName)

        if userexist == True:
            error = "This username is already is use"
            return render_template("login.html", error=error)
        else:
            ucobj = UserClass()
            ucobj.setUserDetails(7, userName, name, pswd, email, phone)
            UserData = BusinessLayer.RegisterUser(ucobj)

            destination = "/".join(
                [APP_STORAGE_PATH, UserData['UserDetails'].userName + "_home"])

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

            return render_template("login.html")

    else:
        return render_template('404.html')
Exemplo n.º 9
0
Arquivo: app.py Projeto: pnjha/DropBox
def allfiles():

    userId = RetrieveSessionDetails('userId')

    UserData = BusinessLayer.getAllFiles(userId)

    userclassInstance = UserClass()
    userclassInstance.setUserDetails(RetrieveSessionDetails('userId'),RetrieveSessionDetails('userName'),"passwd","name","email","phone")
    userclassInstance.setCurrentFolderId('0')
    userclassInstance.setCurrentFolderName("All files")
    userclassInstance.setHomeFolderId(RetrieveSessionDetails('homeFolderId'))

    UserData['UserDetails'] = userclassInstance

    return render_template('index.html',**UserData)
Exemplo n.º 10
0
def search():

    userId = RetrieveSessionDetails('userId')
    fileName = request.form.get('fileName')

    if fileName == '':
        currentFolderId = RetrieveSessionDetails('currentFolderId')
        return redirect(url_for('index', folderId=currentFolderId))

    UserData = BusinessLayer.searchFile(userId, fileName)

    if UserData != None:
        # UserData['searchStatus'] = 'True'

        userclassInstance = UserClass()
        userclassInstance.setUserDetails(RetrieveSessionDetails('userId'),
                                         RetrieveSessionDetails('userName'),
                                         "passwd", "name", "email", "phone")
        userclassInstance.setCurrentFolderId("0")
        userclassInstance.setCurrentFolderName("Search Result")
        userclassInstance.setHomeFolderId(
            RetrieveSessionDetails('homeFolderId'))

        UserData['UserDetails'] = userclassInstance
        UserData["AllFilesource"] = "NotAllFileSource"
        UserData["sourceParameter"] = "searchSource"

        print("Search Result: ", UserData['FileDetails'][0].filename)
        return render_template('index.html', **UserData)
        # return redirect(url_for('indexSearch',folderId = homeFolder.folderid))

    else:
        homeFolder = BusinessLayer.getHomeFolderId(userId)
        # UserData['searchStatus'] = 'False'
        AddToSession('searchResult', 'False')
        return redirect(url_for('index', folderId=homeFolder.folderid))
Exemplo n.º 11
0
Arquivo: app.py Projeto: pnjha/DropBox
def download(fileId,filename):

    path = APP_STORAGE_PATH

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

    path += BusinessLayer.getPathForFile(userId,fileId)
    path += filename
    
    try:
        return send_file(path, as_attachment=True)

    except Exception as e:
        print(e)

    return redirect(url_for('index',folderId = currentFolderId))
Exemplo n.º 12
0
def retrieve_data():

    print("From home.html")

    bLayerObj = bl.BusinessLayer()

    #latitude_temp,longitude_temp,threshold_value = [17.445437,78.3456945,0.0035]
    latitude_temp,longitude_temp,threshold_value = bLayerObj.get_default_location()
    print(latitude_temp,longitude_temp,threshold_value)
    active_user_data = bLayerObj.getBatteryInfoForAllUser()
    location_based_user_data = bLayerObj.getBatteryInfoForAllUserAsPerLocation(latitude_temp,longitude_temp,threshold_value)

    print(location_based_user_data)

    data_dict = {"active_user_data" : active_user_data,"location_based_user_data":location_based_user_data}

    return jsonify(data_dict)
Exemplo n.º 13
0
def index():

    bLayerObj = bl.BusinessLayer()

    networkInfo = bLayerObj.getNetworkDetailsForPresentation()
    wifi = bLayerObj.getWifiDataForPresentation()

    info = {"networkInfo": networkInfo, "wifi": wifi}

    user_list = bLayerObj.getAllUserHashDistinct()

    print("user_list: ", user_list)

    # user_list = ['068fd0571f7cc527d4983d35f0d908d9', 'fde62956f023ab40685ecceee22c402e', 'b50f1867e01b21d3134b0097ecb7990d',
    # '73803249c6667c5af2d51c0dedfae487', 'e251a758734abbefe63347192e64ed9f', 'a269f1b41ae5073302d70baac6137ae2',
    # '34237272481aa6a02ea94799695a6982', '67d97bd65bfff6f9274ef52034fa0e19', '93e2f4935402da5361fcaeb636fc6cd2']

    return render_template("home.html", info=info, user_list=user_list)
Exemplo n.º 14
0
def index():

    bLayerObj = bl.BusinessLayer()

    networkInfo = bLayerObj.getNetworkDetailsForPresentation()
    wifi= bLayerObj.getWifiDataForPresentation()

    info = {
        "networkInfo":networkInfo,
        "wifi":wifi
    }

    user_list = bLayerObj.getAllUserHashDistinct()

    print("user_list: ",user_list)

    

    return render_template("home.html",info = info, user_list = user_list)
Exemplo n.º 15
0
def popular_locations():
    global user_hash_list
    bLayerObj = bl.BusinessLayer()
    user_list = bLayerObj.getAllUserHashDistinct()
    place_list,latitude_list,longitude_list,radius_list = checkdbforpopularlocations()
    row_popular_locations = []
    length = 0
    if(len(radius_list)==0):
        row_popular_locations.append("no data to display")
    else:
        for i in range(0,len(radius_list)):
            temp_list = []
            temp_list.append(place_list[i])
            temp_list.append(latitude_list[i])
            temp_list.append(longitude_list[i])
            temp_list.append(radius_list[i])
            row_popular_locations.append(temp_list)
        length = len(radius_list)

    print("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM")
    print(user_hash_list)
    return render_template('popular_location.html',data=row_popular_locations,length=length,output=user_hash_list,op_length=len(user_hash_list), user_list = user_list)
Exemplo n.º 16
0
Arquivo: app.py Projeto: pnjha/DropBox
#!/usr/bin/python3

from model import db
import os,errno
from flask import Flask, render_template, request, send_from_directory, redirect, url_for, send_file,session
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from ClassStructure import UserClass , FileClass, FolderClass
import BusinessLayer

BusinessLayer = BusinessLayer.BusinessLayer()

app = Flask(__name__)

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db_path = os.path.join(os.path.dirname(__file__), 'dropbox.db')
db_uri = 'sqlite:///{}'.format(db_path)
app.config['SQLALCHEMY_DATABASE_URI'] = db_uri


db = SQLAlchemy(app)
bootstrap = Bootstrap(app)
app.debug = True

app.secret_key = os.urandom(24)

APP_ROOT = os.path.dirname(os.path.abspath(__file__))
APP_STORAGE_PATH = APP_ROOT + str('/Repository/')

@app.route('/')
def landingPage():