|
|
@ -1,5 +1,4 @@ |
|
|
|
from flask import request, flash, redirect, url_for, abort |
|
|
|
from flask_login import login_required |
|
|
|
from flask import request, flash, redirect, url_for |
|
|
|
from app.utils.priv_required import priv_required |
|
|
|
from flask_wtf import FlaskForm |
|
|
|
from wtforms import SubmitField |
|
|
@ -11,11 +10,13 @@ from app import app, db |
|
|
|
import yaml |
|
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin', methods=['GET', 'POST']) |
|
|
|
@priv_required('access-admin-panel') |
|
|
|
def adm(): |
|
|
|
return render('admin/index.html') |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin/groups', methods=['GET', 'POST']) |
|
|
|
@priv_required('access-admin-panel') |
|
|
|
def adm_groups(): |
|
|
@ -57,7 +58,7 @@ def adm_groups(): |
|
|
|
if g is not None: |
|
|
|
member.groups.append(g) |
|
|
|
|
|
|
|
m = Member('PlanèteCasio','contact@planet-casio.com','v5-forever') |
|
|
|
m = Member('PlanèteCasio', 'contact@planet-casio.com', 'v5-forever') |
|
|
|
addgroup(m, "Compte communautaire") |
|
|
|
db.session.add(m) |
|
|
|
|
|
|
@ -72,12 +73,13 @@ def adm_groups(): |
|
|
|
|
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
users = Member.query.all() |
|
|
|
users = Member.query.all() |
|
|
|
groups = Group.query.all() |
|
|
|
|
|
|
|
return render('admin/groups_privileges.html', users=users, groups=groups, |
|
|
|
form=form) |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin/edit-account/<user_id>', methods=['GET', 'POST']) |
|
|
|
@priv_required('edit-account') |
|
|
|
def adm_edit_account(user_id): |
|
|
@ -88,22 +90,22 @@ def adm_edit_account(user_id): |
|
|
|
if form.validate_on_submit(): |
|
|
|
if form.avatar.data: |
|
|
|
f = form.avatar.data |
|
|
|
f.save("./app/static/"+user.avatar) |
|
|
|
f.save("./app/static/" + user.avatar) |
|
|
|
|
|
|
|
newname = form.username.data |
|
|
|
names = list(Member.query.filter(Member.id != user.id).values(Member.name)) |
|
|
|
if newname in names: |
|
|
|
raise Exception(f'{data["name"]} is not available') |
|
|
|
raise Exception(f'{newname} is not available') |
|
|
|
user.update( |
|
|
|
name = form.username.data or None, |
|
|
|
email = form.email.data or None, |
|
|
|
password = form.password.data or None, |
|
|
|
birthday = form.birthday.data, |
|
|
|
signature = form.signature.data, |
|
|
|
bio = form.biography.data, |
|
|
|
newsletter = form.newsletter.data, |
|
|
|
xp = form.xp.data or None, |
|
|
|
innovation = form.innovation.data or None |
|
|
|
name=form.username.data or None, |
|
|
|
email=form.email.data or None, |
|
|
|
password=form.password.data or None, |
|
|
|
birthday=form.birthday.data, |
|
|
|
signature=form.signature.data, |
|
|
|
bio=form.biography.data, |
|
|
|
newsletter=form.newsletter.data, |
|
|
|
xp=form.xp.data or None, |
|
|
|
innovation=form.innovation.data or None |
|
|
|
) |
|
|
|
db.session.merge(user) |
|
|
|
db.session.commit() |
|
|
@ -114,6 +116,7 @@ def adm_edit_account(user_id): |
|
|
|
|
|
|
|
return render('admin/edit_account.html', user=user, form=form) |
|
|
|
|
|
|
|
|
|
|
|
@app.route('/admin/edit-account/<user_id>/delete', methods=['GET', 'POST']) |
|
|
|
@priv_required('delete-account') |
|
|
|
def adm_delete_account(user_id): |
|
|
@ -134,5 +137,5 @@ def adm_delete_account(user_id): |
|
|
|
return redirect(url_for('adm')) |
|
|
|
else: |
|
|
|
flash('Erreur lors de la suppression du compte', 'error') |
|
|
|
del_form.delete.data = False # Force to tick to delete the account |
|
|
|
del_form.delete.data = False # Force to tick to delete the account |
|
|
|
return render('admin/delete_account.html', user=user, del_form=del_form) |