"Various aestetical improvements"
This commit is contained in:
parent
dc96b0d753
commit
fe10a9320e
562
participate.py
562
participate.py
@ -171,6 +171,15 @@ def check_session(func):
|
|||||||
return render_template('login_or_register.html', message='')
|
return render_template('login_or_register.html', message='')
|
||||||
return check
|
return check
|
||||||
|
|
||||||
|
def gen_token(size=42):
|
||||||
|
""" Generate a random token to be stored in session and cookie """
|
||||||
|
token = binascii.hexlify(os.urandom(size))
|
||||||
|
return token
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# User management
|
||||||
|
########################################################################
|
||||||
|
|
||||||
def check_login(login, password):
|
def check_login(login, password):
|
||||||
""" Puts the login verification code here """
|
""" Puts the login verification code here """
|
||||||
hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
|
hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
|
||||||
@ -229,7 +238,7 @@ def register_user(login, password, confirm):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def confirm_user(login, password, link_id):
|
def confirm_user(login, password, link_id):
|
||||||
""" Confirm user """
|
""" Confirm user by setting link_id == None """
|
||||||
if check_confirm(login, password, link_id):
|
if check_confirm(login, password, link_id):
|
||||||
user = Tetawebapp_users.query.filter_by(mail=login).first()
|
user = Tetawebapp_users.query.filter_by(mail=login).first()
|
||||||
setattr(user, 'link_id', None)
|
setattr(user, 'link_id', None)
|
||||||
@ -346,6 +355,21 @@ def get_user_name(user_id):
|
|||||||
print "------------------------------"
|
print "------------------------------"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def check_user_info():
|
||||||
|
""" Check user info and send appropriate message if info are not complete"""
|
||||||
|
message = ''
|
||||||
|
user = Tetawebapp_users.query.filter_by(mail=session['login']).first()
|
||||||
|
name = user.name
|
||||||
|
phone = user.phone
|
||||||
|
diet = user.diet
|
||||||
|
if name == None or phone == None or diet == None or \
|
||||||
|
len(name) == 0 or len(phone) == 0 or len(diet) == 0:
|
||||||
|
message = "Vos informations personnelles ne sont pas complètement renseignées. N'oubliez pas de remplir votre fiche située dans la section 'Mon compte'"
|
||||||
|
return message.decode('utf-8')
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Turns
|
||||||
|
########################################################################
|
||||||
|
|
||||||
def save_turn(role_id, day, start, end, num_slot):
|
def save_turn(role_id, day, start, end, num_slot):
|
||||||
""" Save a new turn """
|
""" Save a new turn """
|
||||||
@ -484,6 +508,9 @@ def turns_list():
|
|||||||
turns.append(('Dimanche', sunday_turns))
|
turns.append(('Dimanche', sunday_turns))
|
||||||
return turns
|
return turns
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Staffs
|
||||||
|
########################################################################
|
||||||
def get_staffs():
|
def get_staffs():
|
||||||
""" """
|
""" """
|
||||||
try:
|
try:
|
||||||
@ -537,6 +564,10 @@ def save_staff_slot(turn_id, slot_id, user_id):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Role
|
||||||
|
########################################################################
|
||||||
|
|
||||||
def get_roles():
|
def get_roles():
|
||||||
""" Get full roles list """
|
""" Get full roles list """
|
||||||
try:
|
try:
|
||||||
@ -549,22 +580,9 @@ def get_roles():
|
|||||||
print "------------------------------"
|
print "------------------------------"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_user_info():
|
########################################################################
|
||||||
""" Check user info and send appropriate message if info are not complete"""
|
# Mail
|
||||||
message = ''
|
########################################################################
|
||||||
user = Tetawebapp_users.query.filter_by(mail=session['login']).first()
|
|
||||||
name = user.name
|
|
||||||
phone = user.phone
|
|
||||||
diet = user.diet
|
|
||||||
if name == None or phone == None or diet == None or \
|
|
||||||
len(name) == 0 or len(phone) == 0 or len(diet) == 0:
|
|
||||||
message = "Vos informations personnelles ne sont pas complètement renseignées. N'oubliez pas de remplir votre fiche située dans la section 'Mon compte'"
|
|
||||||
return message.decode('utf-8')
|
|
||||||
|
|
||||||
def gen_token(size=42):
|
|
||||||
""" Generate a random token to be stored in session and cookie """
|
|
||||||
token = binascii.hexlify(os.urandom(size))
|
|
||||||
return token
|
|
||||||
|
|
||||||
def send_mail(email, link_id):
|
def send_mail(email, link_id):
|
||||||
msg = Message("Confirmation d'inscription au staff THSF",
|
msg = Message("Confirmation d'inscription au staff THSF",
|
||||||
@ -594,6 +612,21 @@ def page_not_found(e):
|
|||||||
""" 404 not found """
|
""" 404 not found """
|
||||||
return render_template('error.html'), 404
|
return render_template('error.html'), 404
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Entry
|
||||||
|
########################################################################
|
||||||
|
@app.route("/", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def index():
|
||||||
|
""" Index page """
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
message = check_user_info()
|
||||||
|
return render_template('index.html', menu=menu, message=message, login=session['login'])
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Session
|
||||||
|
########################################################################
|
||||||
@app.route("/login", methods=['GET', 'POST'])
|
@app.route("/login", methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
""" Login """
|
""" Login """
|
||||||
@ -622,6 +655,9 @@ def login():
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# User
|
||||||
|
########################################################################
|
||||||
@app.route("/confirm/<LINK_ID>", methods=['GET', 'POST'])
|
@app.route("/confirm/<LINK_ID>", methods=['GET', 'POST'])
|
||||||
def confirm(LINK_ID):
|
def confirm(LINK_ID):
|
||||||
""" Index page """
|
""" Index page """
|
||||||
@ -674,15 +710,6 @@ def register():
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
|
||||||
@app.route("/", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def index():
|
|
||||||
""" Index page """
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
message = check_user_info()
|
|
||||||
return render_template('index.html', menu=menu, message=message, login=session['login'])
|
|
||||||
|
|
||||||
@app.route("/account", methods=['GET', 'POST'])
|
@app.route("/account", methods=['GET', 'POST'])
|
||||||
@check_session
|
@check_session
|
||||||
def account():
|
def account():
|
||||||
@ -738,246 +765,10 @@ def logout():
|
|||||||
sync_cookies(response, session)
|
sync_cookies(response, session)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# Admin zone
|
# Staffsheet
|
||||||
########################################################################
|
########################################################################
|
||||||
@app.route("/users", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def list_users():
|
|
||||||
""" Users list """
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
message = check_user_info()
|
|
||||||
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
|
||||||
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
|
||||||
|
|
||||||
@app.route("/account/<ID>", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def account_by_id(ID):
|
|
||||||
""" Arcticles page """
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
message = "ID de l'utilisateur non conforme"
|
|
||||||
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
|
||||||
user_id = int(ID.encode('utf-8'))
|
|
||||||
user = Tetawebapp_users.query.filter_by(id=user_id).first()
|
|
||||||
return render_template('account_by_id.html', menu=menu, user=user)
|
|
||||||
# User is not admin
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except ValueError:
|
|
||||||
# ID is not an integer
|
|
||||||
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
|
||||||
|
|
||||||
@app.route("/account/update/<ID>", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def update_account_by_id(ID):
|
|
||||||
""" Update given account """
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
login = session['login']
|
|
||||||
password = request.form.get('password').encode('utf-8')
|
|
||||||
confirm = request.form.get('confirm').encode('utf-8')
|
|
||||||
name = request.form.get('name').encode('utf-8')
|
|
||||||
phone = request.form.get('phone').encode('utf-8')
|
|
||||||
diet = request.form.get('diet').encode('utf-8')
|
|
||||||
message = "ID de l'utilisateur non conforme"
|
|
||||||
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
|
||||||
user_id = int(ID.encode('utf-8'))
|
|
||||||
if update_user_by_id(user_id, login, password, confirm, name, phone, diet):
|
|
||||||
user = Tetawebapp_users.query.filter_by(id=ID).first()
|
|
||||||
message = check_user_info()
|
|
||||||
else:
|
|
||||||
message = "Erreur lors de l'enregistrement des données."
|
|
||||||
return render_template('account_by_id.html', menu=menu, user=user,message=message)
|
|
||||||
# User is not admin
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except ValueError:
|
|
||||||
# ID is not an integer
|
|
||||||
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
|
||||||
|
|
||||||
@app.route("/account/delete/<ID>", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def delete_account(ID):
|
|
||||||
""" Delete given account """
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
message = "Erreur lors de la suppression.".decode('utf-8')
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
|
||||||
user_id = int(ID.encode('utf-8'))
|
|
||||||
if delete_user(user_id):
|
|
||||||
message = ''
|
|
||||||
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
|
||||||
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
|
||||||
# User is not admin
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except ValueError:
|
|
||||||
# ID is not an integer
|
|
||||||
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
|
||||||
|
|
||||||
@app.route("/turns", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def list_turns():
|
|
||||||
""" List staff turns """
|
|
||||||
try:
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
message = ''
|
|
||||||
if session['is_admin']:
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
turns = turns_list()
|
|
||||||
message = ''
|
|
||||||
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
|
||||||
# TODO:
|
|
||||||
# Here comes the list_turns_by_user_id code
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
|
|
||||||
@app.route("/turn/new", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def new_turn():
|
|
||||||
""" New turn form """
|
|
||||||
tuesday = '2018-05-08'
|
|
||||||
wenesday = '2018-05-09'
|
|
||||||
thirsday = '2018-05-10'
|
|
||||||
friday = '2018-05-11'
|
|
||||||
saturday = '2018-05-12'
|
|
||||||
sunday = '2018-05-13'
|
|
||||||
monday = '2018-05-14'
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
roles = Tetawebapp_roles.query.order_by(Tetawebapp_roles.id).all()
|
|
||||||
days = [('Mardi', tuesday), ('Mercredi', wenesday), ('Jeudi', thirsday), ('Vendredi', friday), ('Samedi', saturday), ('Dimanche', sunday)]
|
|
||||||
return render_template('new_turn.html', menu=menu, page=page, roles=roles, days=days)
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
|
|
||||||
@app.route("/turn/add", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def add_turn():
|
|
||||||
""" Add staff turn """
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
role_id = request.form.get('role_id').encode('utf-8')
|
|
||||||
day = request.form.get('day').encode('utf-8')
|
|
||||||
start = request.form.get('start').encode('utf-8')
|
|
||||||
end = request.form.get('end').encode('utf-8')
|
|
||||||
num_slot = request.form.get('num_slot').encode('utf-8')
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
turns = turns_list()
|
|
||||||
message = "Erreur lors de l'enregistrement.".decode('utf-8')
|
|
||||||
if save_turn(role_id, day, start, end, num_slot):
|
|
||||||
turns = turns_list()
|
|
||||||
message=''
|
|
||||||
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
|
||||||
# User is not admin
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except AttributeError as e:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
|
|
||||||
@app.route("/turn/<ID>", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def turn_by_id(ID):
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
tuesday = '2018-05-08'
|
|
||||||
wenesday = '2018-05-09'
|
|
||||||
thirsday = '2018-05-10'
|
|
||||||
friday = '2018-05-11'
|
|
||||||
saturday = '2018-05-12'
|
|
||||||
sunday = '2018-05-13'
|
|
||||||
monday = '2018-05-14'
|
|
||||||
days = [('Mardi', tuesday), ('Mercredi', wenesday), ('Jeudi', thirsday), ('Vendredi', friday), ('Samedi', saturday), ('Dimanche', sunday)]
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
roles = Tetawebapp_roles.query.order_by(Tetawebapp_roles.id).all()
|
|
||||||
message = 'ID du tour de staff non conforme'
|
|
||||||
turns = turns_list()
|
|
||||||
turn_id = int(ID.encode('utf-8'))
|
|
||||||
turn = get_turn_by_id(turn_id)
|
|
||||||
return render_template('turn_by_id.html', menu=menu, page=page, turn=turn, roles=roles, days=days)
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except ValueError:
|
|
||||||
# ID is not an integer
|
|
||||||
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
|
||||||
|
|
||||||
@app.route("/turn/update/<ID>", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def update_turn(ID):
|
|
||||||
""" Update given staff turn """
|
|
||||||
try:
|
|
||||||
role_id = request.form.get('role_id').encode('utf-8')
|
|
||||||
start = request.form.get('start').encode('utf-8')
|
|
||||||
end = request.form.get('end').encode('utf-8')
|
|
||||||
num_slot = request.form.get('num_slot').encode('utf-8')
|
|
||||||
day = request.form.get('day').encode('utf-8')
|
|
||||||
if session['is_admin']:
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
turns = turns_list()
|
|
||||||
message = "Erreur lors de l'enregistrement.".decode('utf-8')
|
|
||||||
turn_id = int(ID.encode('utf-8'))
|
|
||||||
if update_turn_by_id(turn_id, role_id, day, start, end, num_slot):
|
|
||||||
turns = turns_list()
|
|
||||||
message = ''
|
|
||||||
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
|
||||||
# User is not admin
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except AttributeError as e:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except ValueError:
|
|
||||||
# ID is not an integer
|
|
||||||
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
|
||||||
|
|
||||||
@app.route("/turn/delete/<ID>", methods=['GET', 'POST'])
|
|
||||||
@check_session
|
|
||||||
def delete_turn(ID):
|
|
||||||
""" Delete given staff turn """
|
|
||||||
try:
|
|
||||||
if session['is_admin']:
|
|
||||||
message = 'Erreur lors de la suppression.'
|
|
||||||
page = str(request.url_rule)
|
|
||||||
menu = get_menu(page)
|
|
||||||
turns = turns_list()
|
|
||||||
turn_id = int(ID.encode('utf-8'))
|
|
||||||
if drop_turn(turn_id):
|
|
||||||
message = ''
|
|
||||||
turns = turns_list()
|
|
||||||
return render_template('list_turns.html', menu=menu, turns=turns, message=message)
|
|
||||||
return render_template('list_turns.html', menu=menu, turns=turns, message=message)
|
|
||||||
# User is not admin
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except AttributeError:
|
|
||||||
# User is not logged in
|
|
||||||
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
|
||||||
except ValueError:
|
|
||||||
# ID is not an integer
|
|
||||||
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
|
||||||
|
|
||||||
@app.route("/staffsheet", methods=['GET', 'POST'])
|
@app.route("/staffsheet", methods=['GET', 'POST'])
|
||||||
@check_session
|
@check_session
|
||||||
def staffsheet():
|
def staffsheet():
|
||||||
@ -1161,6 +952,249 @@ def update_staff_slot(TURN_ID, SLOT_ID):
|
|||||||
# At least one ID is not integer
|
# At least one ID is not integer
|
||||||
return render_template('login_or_register.html', message="Identifiants non conformes")
|
return render_template('login_or_register.html', message="Identifiants non conformes")
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Admin zone
|
||||||
|
########################################################################
|
||||||
|
@app.route("/users", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def list_users():
|
||||||
|
""" Users list """
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
message = check_user_info()
|
||||||
|
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
||||||
|
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
||||||
|
|
||||||
|
@app.route("/account/<ID>", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def account_by_id(ID):
|
||||||
|
""" Arcticles page """
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
message = "ID de l'utilisateur non conforme"
|
||||||
|
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
||||||
|
user_id = int(ID.encode('utf-8'))
|
||||||
|
user = Tetawebapp_users.query.filter_by(id=user_id).first()
|
||||||
|
return render_template('account_by_id.html', menu=menu, user=user)
|
||||||
|
# User is not admin
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except ValueError:
|
||||||
|
# ID is not an integer
|
||||||
|
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
||||||
|
|
||||||
|
@app.route("/account/update/<ID>", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def update_account_by_id(ID):
|
||||||
|
""" Update given account """
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
login = session['login']
|
||||||
|
password = request.form.get('password').encode('utf-8')
|
||||||
|
confirm = request.form.get('confirm').encode('utf-8')
|
||||||
|
name = request.form.get('name').encode('utf-8')
|
||||||
|
phone = request.form.get('phone').encode('utf-8')
|
||||||
|
diet = request.form.get('diet').encode('utf-8')
|
||||||
|
message = "ID de l'utilisateur non conforme"
|
||||||
|
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
||||||
|
user_id = int(ID.encode('utf-8'))
|
||||||
|
if update_user_by_id(user_id, login, password, confirm, name, phone, diet):
|
||||||
|
user = Tetawebapp_users.query.filter_by(id=ID).first()
|
||||||
|
message = check_user_info()
|
||||||
|
else:
|
||||||
|
message = "Erreur lors de l'enregistrement des données."
|
||||||
|
return render_template('account_by_id.html', menu=menu, user=user,message=message)
|
||||||
|
# User is not admin
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except ValueError:
|
||||||
|
# ID is not an integer
|
||||||
|
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
||||||
|
|
||||||
|
@app.route("/account/delete/<ID>", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def delete_account(ID):
|
||||||
|
""" Delete given account """
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
message = "Erreur lors de la suppression.".decode('utf-8')
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
||||||
|
user_id = int(ID.encode('utf-8'))
|
||||||
|
if delete_user(user_id):
|
||||||
|
message = ''
|
||||||
|
staffers = Tetawebapp_users.query.filter_by(is_admin=0).order_by(Tetawebapp_users.name).all()
|
||||||
|
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
||||||
|
# User is not admin
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except ValueError:
|
||||||
|
# ID is not an integer
|
||||||
|
return render_template('list_users.html', menu=menu, staffers=staffers, message=message)
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
# Turns
|
||||||
|
########################################################################
|
||||||
|
@app.route("/turns", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def list_turns():
|
||||||
|
""" List staff turns """
|
||||||
|
try:
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
message = ''
|
||||||
|
if session['is_admin']:
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
turns = turns_list()
|
||||||
|
message = ''
|
||||||
|
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
||||||
|
# TODO:
|
||||||
|
# Here comes the list_turns_by_user_id code
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
|
||||||
|
@app.route("/turn/new", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def new_turn():
|
||||||
|
""" New turn form """
|
||||||
|
tuesday = '2018-05-08'
|
||||||
|
wenesday = '2018-05-09'
|
||||||
|
thirsday = '2018-05-10'
|
||||||
|
friday = '2018-05-11'
|
||||||
|
saturday = '2018-05-12'
|
||||||
|
sunday = '2018-05-13'
|
||||||
|
monday = '2018-05-14'
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
roles = Tetawebapp_roles.query.order_by(Tetawebapp_roles.id).all()
|
||||||
|
days = [('Mardi', tuesday), ('Mercredi', wenesday), ('Jeudi', thirsday), ('Vendredi', friday), ('Samedi', saturday), ('Dimanche', sunday)]
|
||||||
|
return render_template('new_turn.html', menu=menu, page=page, roles=roles, days=days)
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
|
||||||
|
@app.route("/turn/add", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def add_turn():
|
||||||
|
""" Add staff turn """
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
role_id = request.form.get('role_id').encode('utf-8')
|
||||||
|
day = request.form.get('day').encode('utf-8')
|
||||||
|
start = request.form.get('start').encode('utf-8')
|
||||||
|
end = request.form.get('end').encode('utf-8')
|
||||||
|
num_slot = request.form.get('num_slot').encode('utf-8')
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
turns = turns_list()
|
||||||
|
message = "Erreur lors de l'enregistrement.".decode('utf-8')
|
||||||
|
if save_turn(role_id, day, start, end, num_slot):
|
||||||
|
turns = turns_list()
|
||||||
|
message=''
|
||||||
|
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
||||||
|
# User is not admin
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except AttributeError as e:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
|
||||||
|
@app.route("/turn/<ID>", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def turn_by_id(ID):
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
tuesday = '2018-05-08'
|
||||||
|
wenesday = '2018-05-09'
|
||||||
|
thirsday = '2018-05-10'
|
||||||
|
friday = '2018-05-11'
|
||||||
|
saturday = '2018-05-12'
|
||||||
|
sunday = '2018-05-13'
|
||||||
|
monday = '2018-05-14'
|
||||||
|
days = [('Mardi', tuesday), ('Mercredi', wenesday), ('Jeudi', thirsday), ('Vendredi', friday), ('Samedi', saturday), ('Dimanche', sunday)]
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
roles = Tetawebapp_roles.query.order_by(Tetawebapp_roles.id).all()
|
||||||
|
message = 'ID du tour de staff non conforme'
|
||||||
|
turns = turns_list()
|
||||||
|
turn_id = int(ID.encode('utf-8'))
|
||||||
|
turn = get_turn_by_id(turn_id)
|
||||||
|
return render_template('turn_by_id.html', menu=menu, page=page, turn=turn, roles=roles, days=days)
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except ValueError:
|
||||||
|
# ID is not an integer
|
||||||
|
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
||||||
|
|
||||||
|
@app.route("/turn/update/<ID>", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def update_turn(ID):
|
||||||
|
""" Update given staff turn """
|
||||||
|
try:
|
||||||
|
role_id = request.form.get('role_id').encode('utf-8')
|
||||||
|
start = request.form.get('start').encode('utf-8')
|
||||||
|
end = request.form.get('end').encode('utf-8')
|
||||||
|
num_slot = request.form.get('num_slot').encode('utf-8')
|
||||||
|
day = request.form.get('day').encode('utf-8')
|
||||||
|
if session['is_admin']:
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
turns = turns_list()
|
||||||
|
message = "Erreur lors de l'enregistrement.".decode('utf-8')
|
||||||
|
turn_id = int(ID.encode('utf-8'))
|
||||||
|
if update_turn_by_id(turn_id, role_id, day, start, end, num_slot):
|
||||||
|
turns = turns_list()
|
||||||
|
message = ''
|
||||||
|
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
||||||
|
# User is not admin
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except AttributeError as e:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except ValueError:
|
||||||
|
# ID is not an integer
|
||||||
|
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
||||||
|
|
||||||
|
@app.route("/turn/delete/<ID>", methods=['GET', 'POST'])
|
||||||
|
@check_session
|
||||||
|
def delete_turn(ID):
|
||||||
|
""" Delete given staff turn """
|
||||||
|
try:
|
||||||
|
if session['is_admin']:
|
||||||
|
message = 'Erreur lors de la suppression.'
|
||||||
|
page = str(request.url_rule)
|
||||||
|
menu = get_menu(page)
|
||||||
|
turns = turns_list()
|
||||||
|
turn_id = int(ID.encode('utf-8'))
|
||||||
|
if drop_turn(turn_id):
|
||||||
|
message = ''
|
||||||
|
turns = turns_list()
|
||||||
|
return render_template('list_turns.html', menu=menu, turns=turns, message=message)
|
||||||
|
return render_template('list_turns.html', menu=menu, turns=turns, message=message)
|
||||||
|
# User is not admin
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except AttributeError:
|
||||||
|
# User is not logged in
|
||||||
|
return render_template('login_or_register.html', message="Utilisateur ou mot de passe invalide")
|
||||||
|
except ValueError:
|
||||||
|
# ID is not an integer
|
||||||
|
return render_template('list_turns.html', menu=menu, page=page, turns=turns, message=message)
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# Main
|
# Main
|
||||||
########################################################################
|
########################################################################
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
<h3>Informations du compte</h3>
|
<h3>Informations du compte</h3>
|
||||||
<form method='POST' action='/account/update/{{ user.id }}'>
|
<form method='POST' action='/account/update/{{ user.id }}'>
|
||||||
<label>Adresse email: </label><input id='login' name='login' type='text' value='{{ user.mail }}' disabled='disabled' required/><br/>
|
<label>Adresse email: </label><input id='login' name='login' type='text' value='{{ user.mail }}' disabled='disabled' required/><br/>
|
||||||
<label>Prénom ou pseudo: </label><input id='name' name='name' type='text' value='{{ user.name }}'/><br/>
|
<label>Prénom ou pseudo: </label><input id='name' name='name' type='text' value='{{ user.name or '' }}'/><br/>
|
||||||
<label>Nouveau mot de passe: </label><input id='password' name='password' type='password'/><br/>
|
<label>Nouveau mot de passe: </label><input id='password' name='password' type='password'/><br/>
|
||||||
<label>Confirmation mot de passe: </label><input id='confirm' name='confirm' type='password'/><br/>
|
<label>Confirmation mot de passe: </label><input id='confirm' name='confirm' type='password'/><br/>
|
||||||
<label>Numéro de téléphone: </label><input id='phone' name='phone' type='text' value='{{ user.phone }}'/><br/>
|
<label>Numéro de téléphone: </label><input id='phone' name='phone' type='text' value='{{ user.phone or '' }}'/><br/>
|
||||||
<label>Régime alimentaire et remarques: </label><input id='diet' name='diet' type='text' value='{{ user.diet }}'/><br/>
|
<label>Régime alimentaire et remarques: </label><input id='diet' name='diet' type='text' value='{{ user.diet or '' }}'/><br/>
|
||||||
<input type='submit' value='Update' onclick='javascript:return update_account();'>
|
<input type='submit' value='Update' onclick='javascript:return update_account();'>
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
<a href='http://mixart-myrys.org'>Mix'Art Myrys</a>.
|
<a href='http://mixart-myrys.org'>Mix'Art Myrys</a>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Ce festival ne pourrait pas avoir lieu sans votre implication et cette année encore votre aide est la bienvenue et nous
|
Ce festival ne pourrait pas avoir lieu sans votre implication et cette année encore <strong>votre aide est la bienvenue et nous
|
||||||
est précieuse.
|
est précieuse</strong>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Ce site vous permettra:
|
Ce site vous permettra:
|
||||||
@ -47,9 +47,9 @@
|
|||||||
</article>
|
</article>
|
||||||
<article class='left'>
|
<article class='left'>
|
||||||
<form method='POST' action='/login'>
|
<form method='POST' action='/login'>
|
||||||
<label>Adresse mail: </label><input id='login' name='login' type='text' /><br/>
|
<label>Adresse mail: </label><input id='login' name='login' type='text' required /><br/>
|
||||||
<label>Mot de passe: </label><input id='password' name='password' type='password' /><br/>
|
<label>Mot de passe: </label><input id='password' name='password' type='password' required /><br/>
|
||||||
<input type='submit' value='Log me in'>
|
<input type='submit' value='Connexion'>
|
||||||
</form>
|
</form>
|
||||||
<p class='note'>
|
<p class='note'>
|
||||||
Mot de passe oublié ? Envoyez une <a href='https://bofh.tetalab.org/?do=newtask&project=2'>demande de réinitialisation de votre mot de passe</a>.
|
Mot de passe oublié ? Envoyez une <a href='https://bofh.tetalab.org/?do=newtask&project=2'>demande de réinitialisation de votre mot de passe</a>.
|
||||||
@ -64,7 +64,7 @@
|
|||||||
<label>Adresse mail: </label><input id='reg_mail' name='login' type='text' required /><br/>
|
<label>Adresse mail: </label><input id='reg_mail' name='login' type='text' required /><br/>
|
||||||
<label>Mot de passe (8 char min.): </label><input id='reg_password' name='password' type='password' required /><br/>
|
<label>Mot de passe (8 char min.): </label><input id='reg_password' name='password' type='password' required /><br/>
|
||||||
<label>Confirmation: </label><input id='reg_confirm' name='confirm' type='password' required /><br/>
|
<label>Confirmation: </label><input id='reg_confirm' name='confirm' type='password' required /><br/>
|
||||||
<input type='submit' value='Register me NOW !'>
|
<input type='submit' value='Enregistrement'>
|
||||||
</form>
|
</form>
|
||||||
<p class='note'>En vous inscrivant vous déclarez être prèt à découvrir l'insondabilité de l'improbable</p>
|
<p class='note'>En vous inscrivant vous déclarez être prèt à découvrir l'insondabilité de l'improbable</p>
|
||||||
</article>
|
</article>
|
||||||
|
Loading…
Reference in New Issue
Block a user