Final Changes to make the app functionnal

This commit is contained in:
Michel V 2020-06-25 13:08:48 +02:00
parent 533ab8e8e1
commit 00b25b0de1
8 changed files with 97 additions and 72 deletions

View File

@ -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

View File

@ -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/<id>')
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/<id>')
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():

View File

@ -1,9 +1,9 @@
<html>
<head>
{% if title %}
<title>{{ title }} - {{ dico['nameApp'] }}</title>
<title>{{ title }} - {{ dico['nameApp'] }}</title>
{% else %}
<title>{{ dico['nameApp'] }}</title>
<title>{{ dico['nameApp'] }}</title>
{% endif %}
</head>
<body>
@ -11,24 +11,25 @@
{{ dico['nameApp'] }}
<a href="{{ url_for('home') }}">{{ dico['nameHome'] }}</a>
{% if userlogged.is_authenticated == False %}
<a href="{{ url_for('login') }}">{{ dico['nameLogin'] }}</a>
<a href="{{ url_for('login') }}">{{ dico['nameLogin'] }}</a>
{% else %}
<a href="{{ url_for('upload') }}">{{ dico['nameUpload'] }}</a>
{% if userlogged.isAdmin == True %}
<a href="{{ url_for('register') }}">{{ dico['nameRegister'] }}</a>
{% endif %}
<a href="{{ url_for('logout') }}">{{ dico['termLogout'] }}</a>
<a href="{{ url_for('upload') }}">{{ dico['nameUpload'] }}</a>
{% if userlogged.isAdmin == True %}
<a href="{{ url_for('register') }}">{{ dico['nameRegister'] }}</a>
{% endif %}
<a href="{{ url_for('view') }}">{{ dico['termFiles'] }}</a>
<a href="{{ url_for('logout') }}">{{ dico['termLogout'] }}</a>
{% endif %}
{{ userlogged.username }}
<hr>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
{% block content %}
{% endblock %}

View File

@ -1,10 +1,10 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Hi!</h1>
<p>This site is under development with the original name 'Pycloud'.<br>
It will be a cloud.
</p>
</div>
<div>
<h1>Hi!</h1>
<p>This site is under development with the original name 'Pycloud'.<br>
It will be a cloud.
</p>
</div>
{% endblock %}

View File

@ -1,17 +1,17 @@
{% extends 'base.html' %}
{% block content %}
<form action="" method="POST" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username() }}</p>
<p>
{{ form.password.label }}<br>
{{ form.password() }}</p>
<p>
{{ form.remember_me() }}
{{ form.remember_me.label }}</p>
<p>{{ form.submit() }}</p>
</form>
<form action="" method="POST" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username() }}</p>
<p>
{{ form.password.label }}<br>
{{ form.password() }}</p>
<p>
{{ form.remember_me() }}
{{ form.remember_me.label }}</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}

View File

@ -1,27 +1,27 @@
{% extends 'base.html' %}
{% block content %}
<form action="" method="POST" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username() }}
{% for error in form.username.errors %}
<br>{{ error }}
{% endfor %}
</p>
<p>
{{ form.password.label }}<br>
{{ form.password() }}
</p>
<p>
{{ form.repeatpassword.label }}<br>
{{ form.repeatpassword() }}
</p>
<p>
{{ form.isAdmin() }}
{{ form.isAdmin.label }}
</p>
<p>{{ form.submit() }}</p>
</form>
<form action="" method="POST" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username() }}
{% for error in form.username.errors %}
<br>{{ error }}
{% endfor %}
</p>
<p>
{{ form.password.label }}<br>
{{ form.password() }}
</p>
<p>
{{ form.repeatpassword.label }}<br>
{{ form.repeatpassword() }}
</p>
<p>
{{ form.isAdmin() }}
{{ form.isAdmin.label }}
</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}

View File

@ -1,9 +1,9 @@
{% extends 'base.html' %}
{% block content %}
<form action="" method="POST" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<p>{{ form.uploadfile() }}</p>
<p>{{ form.submit() }}</p>
</form>
<form action="" method="POST" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<p>{{ form.uploadfile() }}</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}

View File

@ -1,9 +1,17 @@
{% extends 'base.html' %}
{% block content %}
<div>
{% for file in files %}
<p>| <a href="{{ url_for('download', id=file.id)}}">{{ file.name }}</a>, {{ file.user.username }} |</p>
{% endfor %}
</div>
{% if files %}
<div>
{% for file in files %}
<p>| <a href="{{ url_for('download', id=file.id)}}">{{ file.name }}</a>, {{ file.user.username }} |</p>
{% endfor %}
</div>
{% else %}
<div>
{% for user in users %}
<a href="{{ url_for('viewAdmin', id = user.id) }}">{{ user.username }}{{ dico['termSFolder'] }}</a>
{% endfor %}
</div>
{% endif %}
{% endblock %}