From b3f13399a41738c17dfb6902b9ca5eaa3156f12f Mon Sep 17 00:00:00 2001 From: piair Date: Mon, 21 Aug 2023 21:25:05 +0200 Subject: [PATCH] =?UTF-8?q?aucune=20id=C3=A9e=20de=20ce=20que=20je=20fais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Flask/app.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Flask/app.py b/Flask/app.py index adb29af..71cefd0 100644 --- a/Flask/app.py +++ b/Flask/app.py @@ -165,7 +165,7 @@ def change_password(): # handle login failed @app.errorhandler(401) -def page_not_found(e): +def unauthorized(e): return(render_template("login.html")) @@ -416,8 +416,9 @@ def download(filename): print("file send !") return send_from_directory(directory='/app/MsRewards-Reborn/user_data/', path=filename, as_attachment=True) -ALLOWED_EXTENSIONS = ["json"] + def allowed_file(filename): + ALLOWED_EXTENSIONS = ["json"] return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @@ -425,22 +426,24 @@ def allowed_file(filename): @login_required def upload_file(): print(request.files) - print(request) - # check if the post request has the file part - if 'file1' not in request.files: - print('No file part') - return redirect(url_for('settings_get')) - file = request.files['file1'] - # If the user does not select a file, the browser submits an - # empty file without a filename. - if file.filename == '': - print('No selected file') - return redirect(url_for('settings_get')) - if file and allowed_file(file.filename): - filename = secure_filename(file.filename) - file.save(os.path.join('/app/MsRewards-Reborn/user_data/', filename)) - return redirect(url_for('settings_get')) + i = 1 + while f'file{i}' in request.files : + file = request.files[f'file{i}'] + if file.filename == '': + print('end of files') + return redirect(url_for('settings_get')) + elif file and allowed_file(file.filename): + filename = secure_filename(file.filename) + print(os.path.join('/app/MsRewards-Reborn/user_data/', filename)) + file.save(os.path.join('/app/MsRewards-Reborn/user_data/', filename)) + + i += 1 + print("requete bizarre") + return redirect(url_for('settings_get')) + + + return redirect(url_for('settings_get')) def maxi(dict):