From 00b25b0de106c4ecca078bc0af796c7e2a4f16b1 Mon Sep 17 00:00:00 2001 From: Michel V Date: Thu, 25 Jun 2020 13:08:48 +0200 Subject: [PATCH] Final Changes to make the app functionnal --- app/__init__.py | 7 +++++- app/routes.py | 19 +++++++++++---- app/templates/base.html | 31 +++++++++++++------------ app/templates/home.html | 12 +++++----- app/templates/login.html | 26 ++++++++++----------- app/templates/register.html | 46 ++++++++++++++++++------------------- app/templates/upload.html | 10 ++++---- app/templates/view.html | 18 +++++++++++---- 8 files changed, 97 insertions(+), 72 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 66d5e8a..fe1e549 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -21,8 +21,10 @@ words = { 'nameView' : 'View', 'nameRegister' : 'Register', 'termLogout' : 'Logout', + 'termSFolder' : "'s folder", 'termChoose' : 'Choose a directory', 'termSubmit' : 'Submit', + 'termFiles' : 'Files', 'termUsername' : 'Username', 'termPassword' : 'Password', 'termRepeatPassword' : 'Repeat Password', @@ -31,7 +33,10 @@ words = { 'termRegistered' : 'Registered: ', 'ErrorInvalid' : 'Invalid Password or Username', 'ErrorUsername' : 'Username already used', - 'ErrorNoFiles' : 'There is no files which belong to this user' + 'ErrorNoFiles' : 'There is no files which belong to this user', + 'ErrorId' : 'This ID reffer to nothing', + 'ErrorPermission' : "You don't have the permission to acces to this page", + 'ErrorLogged' : 'You have to be logged in to acces to this page' } from app import routes, models \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index c2ebdcb..76f2177 100644 --- a/app/routes.py +++ b/app/routes.py @@ -54,8 +54,10 @@ def logout(): @app.route('/register', methods=['GET', 'POST']) def register(): if not current_user.is_authenticated: + flash(words['ErrorLogged']) return redirect(url_for('home')) if current_user.isAdmin == False: + flash(words['ErrorPermission']) return redirect(url_for('home')) form = RegisterForm() if form.validate_on_submit(): @@ -76,6 +78,7 @@ def register(): @app.route('/upload', methods=['GET', 'POST']) def upload(): if not current_user.is_authenticated: + flash(words['ErrorLogged']) return redirect(url_for('home')) form = UploadForm() if form.validate_on_submit(): @@ -96,24 +99,29 @@ def upload(): @app.route('/download/') def download(id): if not current_user.is_authenticated: + flash(words['ErrorLogged']) return redirect(url_for('home')) filetodb = File.query.filter_by(id=id).first() if not filetodb: + flash(words['ErrorId']) return redirect(url_for('home')) if filetodb.user == current_user or current_user.isAdmin == True: return send_from_directory(os.path.join(app.config['FILES_DIR'], filetodb.user.username), filetodb.name, as_attachment=True) else: + flash(words['ErrorPermission']) return redirect(url_for('home')) -# Users' View Page +# View Page # It will show all files which belong to the requested user -# Redirect automatically to the home page if the user isn't logged in or is an Admin +# If the user is an Admin, if will show a page with all users folders +# Redirect automatically to the home page if the user isn't logged in @app.route('/view') -def viewUser(): +def view(): if not current_user.is_authenticated: + flash(words['ErrorLogged']) return redirect(url_for('home')) if current_user.isAdmin: - return redirect(url_for('home')) + return render_template('view.html', title=words['nameView'], dico=words, userlogged=current_user, users = User.query.all()) files = [] for filefromdb in File.query.all(): if filefromdb.user == current_user: @@ -130,11 +138,14 @@ def viewUser(): @app.route('/view/') def viewAdmin(id): if not current_user.is_authenticated: + flash(words['ErrorLogged']) return redirect(url_for('home')) if not current_user.isAdmin: + flash(words['ErrorPermission']) return redirect(url_for('home')) user = User.query.filter_by(id=id).first() if not user: + flash(words['ErrorId']) return redirect(url_for('home')) files = [] for filefromdb in File.query.all(): diff --git a/app/templates/base.html b/app/templates/base.html index c43c823..4def8ea 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -1,9 +1,9 @@ {% if title %} - {{ title }} - {{ dico['nameApp'] }} + {{ title }} - {{ dico['nameApp'] }} {% else %} - {{ dico['nameApp'] }} + {{ dico['nameApp'] }} {% endif %} @@ -11,24 +11,25 @@ {{ dico['nameApp'] }} {{ dico['nameHome'] }} {% if userlogged.is_authenticated == False %} - {{ dico['nameLogin'] }} + {{ dico['nameLogin'] }} {% else %} - {{ dico['nameUpload'] }} - {% if userlogged.isAdmin == True %} - {{ dico['nameRegister'] }} - {% endif %} - {{ dico['termLogout'] }} + {{ dico['nameUpload'] }} + {% if userlogged.isAdmin == True %} + {{ dico['nameRegister'] }} + {% endif %} + {{ dico['termFiles'] }} + {{ dico['termLogout'] }} {% endif %} {{ userlogged.username }}
{% with messages = get_flashed_messages() %} - {% if messages %} -
    - {% for message in messages %} -
  • {{ message }}
  • - {% endfor %} -
- {% endif %} + {% if messages %} +
    + {% for message in messages %} +
  • {{ message }}
  • + {% endfor %} +
+ {% endif %} {% endwith %} {% block content %} {% endblock %} diff --git a/app/templates/home.html b/app/templates/home.html index b06025d..e8fa9cc 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -1,10 +1,10 @@ {% extends 'base.html' %} {% block content %} -
-

Hi!

-

This site is under development with the original name 'Pycloud'.
- It will be a cloud. -

-
+
+

Hi!

+

This site is under development with the original name 'Pycloud'.
+ It will be a cloud. +

+
{% endblock %} \ No newline at end of file diff --git a/app/templates/login.html b/app/templates/login.html index b8a0a76..e9c6f0a 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -1,17 +1,17 @@ {% extends 'base.html' %} {% block content %} -
- {{ form.hidden_tag() }} -

- {{ form.username.label }}
- {{ form.username() }}

-

- {{ form.password.label }}
- {{ form.password() }}

-

- {{ form.remember_me() }} - {{ form.remember_me.label }}

-

{{ form.submit() }}

-
+
+ {{ form.hidden_tag() }} +

+ {{ form.username.label }}
+ {{ form.username() }}

+

+ {{ form.password.label }}
+ {{ form.password() }}

+

+ {{ form.remember_me() }} + {{ form.remember_me.label }}

+

{{ form.submit() }}

+
{% endblock %} \ No newline at end of file diff --git a/app/templates/register.html b/app/templates/register.html index e63ac46..42ef640 100644 --- a/app/templates/register.html +++ b/app/templates/register.html @@ -1,27 +1,27 @@ {% extends 'base.html' %} {% block content %} -
- {{ form.hidden_tag() }} -

- {{ form.username.label }}
- {{ form.username() }} - {% for error in form.username.errors %} -
{{ error }} - {% endfor %} -

-

- {{ form.password.label }}
- {{ form.password() }} -

-

- {{ form.repeatpassword.label }}
- {{ form.repeatpassword() }} -

-

- {{ form.isAdmin() }} - {{ form.isAdmin.label }} -

-

{{ form.submit() }}

-
+
+ {{ form.hidden_tag() }} +

+ {{ form.username.label }}
+ {{ form.username() }} + {% for error in form.username.errors %} +
{{ error }} + {% endfor %} +

+

+ {{ form.password.label }}
+ {{ form.password() }} +

+

+ {{ form.repeatpassword.label }}
+ {{ form.repeatpassword() }} +

+

+ {{ form.isAdmin() }} + {{ form.isAdmin.label }} +

+

{{ form.submit() }}

+
{% endblock %} \ No newline at end of file diff --git a/app/templates/upload.html b/app/templates/upload.html index ea57f17..1c79ddb 100644 --- a/app/templates/upload.html +++ b/app/templates/upload.html @@ -1,9 +1,9 @@ {% extends 'base.html' %} {% block content %} -
- {{ form.hidden_tag() }} -

{{ form.uploadfile() }}

-

{{ form.submit() }}

-
+
+ {{ form.hidden_tag() }} +

{{ form.uploadfile() }}

+

{{ form.submit() }}

+
{% endblock %} \ No newline at end of file diff --git a/app/templates/view.html b/app/templates/view.html index c5d0137..9d5e74c 100644 --- a/app/templates/view.html +++ b/app/templates/view.html @@ -1,9 +1,17 @@ {% extends 'base.html' %} {% block content %} -
-{% for file in files %} -

| {{ file.name }}, {{ file.user.username }} |

-{% endfor %} -
+ {% if files %} +
+ {% for file in files %} +

| {{ file.name }}, {{ file.user.username }} |

+ {% endfor %} +
+ {% else %} +
+ {% for user in users %} + {{ user.username }}{{ dico['termSFolder'] }} + {% endfor %} +
+ {% endif %} {% endblock %} \ No newline at end of file