Пример #1
0
def token(token):
    # token check
    if DatabaseHelper().validateToken(token):
        data = json.loads(DatabaseHelper().fetchAllFiles(token))
        return data
    else:
        return ""
Пример #2
0
def logout():
    token = request.cookies.get("token")
    # token check
    if DatabaseHelper().validateToken(token):
        # if the users token is in the database then delete the user remove the user token from cookies and db
        DatabaseHelper().removeToken(token)
        resp = make_response(redirect("http://localhost:5000/"))
        resp.set_cookie('token', '', expires=0)
        return resp
    else:
        return make_response(redirect("http://localhost:5000/"))
Пример #3
0
def dashboard():
    token = request.cookies.get("token")
    # add token / identity check
    if DatabaseHelper().validateToken(token):
        return render_template("dashboard.html")
    else:
        return make_response(redirect("http://localhost:5000/"))
Пример #4
0
def insights():
    token = request.cookies.get("token")
    # token check
    if DatabaseHelper().validateToken(token):
        return render_template("insights.html")
    else:
        return make_response(redirect("http://localhost:5000/"))
Пример #5
0
def uploadPage():
    # showing the upload page
    token = request.cookies.get("token")
    # add token / identity check
    if DatabaseHelper().validateToken(token):
        return render_template("upload.html")
    else:
        return make_response(redirect("http://localhost:5000/"))
Пример #6
0
def upload_file():
    token = request.cookies.get("token")
    if request.method == 'POST':
        f = request.files['file']
        fname = secure_filename(f.filename)
        f.save(os.path.join(app.config['UPLOAD_FOLDER'], fname))
        # adding filename to the list
        DatabaseHelper().addFileToList(fname, token)
        return make_response(redirect("http://localhost:5000/dashboard"))
Пример #7
0
def login():
    # checking if the user has a token
    token = request.cookies.get("token")
    # if the token is not empty
    if token != None:
        # validate token
        if DatabaseHelper().validateToken(token):
            # if valid redirect to dashboard
            return make_response(redirect("http://localhost:5000/dashboard"))
        else:
            # show login page
            return render_template("login.html")        
    else:
        # show login page
        return render_template("login.html")
Пример #8
0
def validiate():
    # if the requset is POST
    if request.method == "POST":
        # getting email and password
        email = request.form["email"]
        password = request.form["password"]
        # if valid credentials return new token
        token = DatabaseHelper().validateCredentials(email, password)
        # if the token is issued
        if token:
            # redirect to dashboard
            resp = make_response(redirect("http://localhost:5000/dashboard"))
            resp.set_cookie('token', token)
            return resp
        elif token == None:
            # if no token is issed likely invalid credentials
            return make_response(redirect("http://localhost:5000/"))
    # if the method is not post redirect the user to home page
    else:
        return make_response(redirect("http://localhost:5000/"))
Пример #9
0
from db_helper import DatabaseHelper

if __name__ == "__main__":
    db_manager = DatabaseHelper()
    db_manager.create_users_table()
    db_manager.insert_values_users_table("Franco")