-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
90 lines (74 loc) · 3.06 KB
/
Copy pathcontroller.py
File metadata and controls
90 lines (74 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from flask import Flask , render_template ,request , send_file
import os
from Authentificate import Authentication
from Directory import GsDirectory
from Authentificate import Account
authentification : Authentication
currentPath : str = ""
fixUsername : str = ""
gsDF = GsDirectory()
account = Account()
app = Flask(__name__,template_folder="templates",static_folder = 'static')
@app.route("/")
def Login():
return render_template("login.html")
@app.route('/logout')
def lougout():
return render_template("login.html")
@app.route("/authentification",methods =["GET","POST"])
def home():
global fixUsername
global currentPath
username : str = request.form['username']
password : str = request.form['password']
authentification = Authentication(username,password)
if username != "" :
if authentification.authentification() == True:
fixUsername = username
currentPath = "/home/"+username
return render_template("index.html", directory = gsDF.chemin("/home/"+username))
return render_template("login.html",erreur = "username or password incorrect")
@app.route('/addAccount',methods =["GET","POST"])
def createAccount():
if request.method == 'GET':
return render_template("createAccount.html")
else :
username : str = request.form['username']
password : str = request.form['password']
password2 : str = request.form['password2']
if password != password2 :
return render_template("createAccount.html",erreur = "password incorrect")
if account.addAccount(username,password) == False :
return render_template("createAccount.html",erreur = "username already exists")
return render_template("index.html",directory = gsDF.chemin("/home/"+username))
@app.route('/nbrfiles')
def nbrfiles():
return render_template("index.html",directory = gsDF.chemin(currentPath),fil = str(gsDF.getnbrFichier(currentPath)))
@app.route('/nbrdir')
def nbrdirs():
return render_template("index.html",directory = gsDF.chemin(currentPath),dir = str(gsDF.getnbrDirectory(currentPath)))
@app.route('/space')
def space():
return render_template("index.html",directory = gsDF.chemin(currentPath),spa = str(gsDF.getsize(currentPath)))
@app.route('/search',methods =["GET","POST"])
def Search():
filename : str = request.form['search']
return render_template("index.html",directory = gsDF.rechercheFilesName(currentPath,filename))
@app.route("/download")
def download():
gsDF.download(fixUsername)
return send_file("/home/"+fixUsername+"/"+fixUsername+".zip", as_attachment=True)
@app.route('/<path:path>/',methods =["GET"])
def routefolders(path):
try :
global currentPath
currentPath = "/"+path
if os.path.isdir(currentPath):
return render_template("index.html",directory = gsDF.chemin(currentPath))
elif os.path.isfile(currentPath):
f = open(currentPath)
return render_template("index.html",text = f.read())
except :
return "erreur"
if __name__ == '__main__':
app.run()