-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
134 lines (122 loc) · 5.29 KB
/
Copy pathcontroller.py
File metadata and controls
134 lines (122 loc) · 5.29 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from flask import Flask, render_template, request, redirect, url_for, session, flash
import os
from business import Business
#################################################
import logging
logger = logging.getLogger('myapp')
logger.setLevel(logging.INFO)
handler = logging.FileHandler('app.log')
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
###########################################################
app = Flask(__name__)
app.secret_key = os.urandom(24)
currentPath=""
@app.route('/')
def application():
return redirect(url_for('Login'))
@app.route('/signUpp')
def signUpp():
return render_template('signUp.html')
@app.route('/Login')
def Login():
return render_template('login.html')
@app.route('/index')
def index():
return render_template('index.html',dirs=Business.getDirectoriesall(session['username']))
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['login']
password = request.form['password']
if Business.Authentication(username,password):
session['username'] = username
global currentPath
currentPath=username
flash('You were successfully logged in')
logger.info(f'{username} logged in')
path = session['username']
return redirect(url_for('index'))
flash('Invalid username or password')
logger.warning(f'Invalid login attempt for user {username}')
return redirect(url_for('Login'))
@app.route('/logout',methods=['GET', 'POST'])
def logout():
username = session['username']
global currentPath
currentPath=""
session.pop('username', None)
flash('You were successfully logged out')
logger.info(f'{username} logged out')
return redirect(url_for('Login'))
@app.route('/signUp',methods=['GET', 'POST'])
def signUp():
print("*********************************************")
if request.method == 'POST':
username = request.form['login']
password = request.form['password']
if Business.creation(username,password):
session['username'] = username
global currentPath
currentPath=username
flash('You were successfully signed up')
logger.info(f'{username} signed up')
path = session['username']
return render_template('index.html',dirs=Business.getDirectoriesall(path))
flash('Invalid username or password')
logger.warning(f'Invalid sign up attempt for user {username}')
return render_template('signUp.html',error_auth="failed")
@app.route('/Index', methods=['POST'])
def Index():
global currentPath
path = currentPath
user=session['username']
if request.method == 'POST':
button = request.form['button']
text=request.form['input']
if button.split(' ')[0] == 'back':
if(currentPath.find('/')!=-1):
currentPath=currentPath[0:currentPath.rfind('/')]
path=currentPath
return render_template('index.html', dirs=Business.getDirectoriesall(path))
else:
path=currentPath
return render_template('index.html', dirs=Business.getDirectoriesall(path))
elif button.split(' ')[0] == 'user':
currentPath=user
path=currentPath
return render_template('index.html', dirs=Business.getDirectoriesall(path))
elif button.split(' ')[0] == 'directories':
dirs = Business.getDirectories(path)
return render_template('index.html',dirs=Business.getDirectories(path), var='nombre des dossiers : '+str(len(dirs)))
elif button.split(' ')[0] == 'files':
files = Business.getFiles(path)
return render_template('index.html',dirs=Business.getFiles(path), var='nombre des fichiers : '+str(len(files)))
elif button.split(' ')[0] == 'space':
total = Business.total_size(path)
return render_template('index.html',dirs=Business.getDirectoriesall(path), var='Espace disk utilise : '+str(total)+" ko")
elif button.split(' ')[0] == 'logout':
return redirect(url_for('logout'))
elif button.split(' ')[0] == 'rechercher':
if(currentPath.find('/')!=-1):
dirs=Business.rechercher(currentPath[0:currentPath.find('/')],text)
else:
dirs=Business.rechercher(currentPath,text)
if len(dirs)>0:
return render_template('index.html', dirs=dirs)
elif button.split(' ')[0] =='download':
Business.downloadHome(user)
flash('You have downloaded the file')
logger.info(f'{user} downloaded the file')
else:
logger.info(f'{user} enter to view file {button}')
if os.path.isfile(button.split(' ')[1]):
return render_template('viewFile.html',file=button.split(' ')[0],content=Business.getContent(button.split(' ')[1]))
else:
currentPath=os.path.join(path,button.split(' ')[0])
path=currentPath
return render_template('index.html',dirs=Business.getDirectoriesall(path))
if __name__ == '__main__':
app.run(debug=True)