La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.8 KiB

from flask import flash, redirect, url_for
from app.utils.priv_required import priv_required
from app.models.users import Member
from app.models.trophies import Trophy
from app.forms.account import AdminUpdateAccountForm, AdminDeleteAccountForm, \
AdminAccountAddTrophyForm, AdminAccountDelTrophyForm
from app.utils.render import render
from app import app, db
@app.route('/admin/account/<user_id>/edit', methods=['GET', 'POST'])
@priv_required('access-admin-panel', 'edit-account')
def adm_edit_account(user_id):
user = Member.query.filter_by(id=user_id).first_or_404()
form = AdminUpdateAccountForm(prefix="user")
addtrophy_form = AdminAccountAddTrophyForm(prefix="addtrophy")
addtrophy_form.trophy.choices = [(, for t in Trophy.query.all()]
deltrophy_form = AdminAccountDelTrophyForm(prefix="deltrophy")
deltrophy_form.trophy.choices = [(, for t in user.trophies]
if form.validate_on_submit():
f ="./app/static/" + user.avatar)
newname =
names = list(Member.query.filter( !=
if newname in names:
raise Exception(f'{newname} is not available')
user.update( or None, or None, or None,,,,, or None,
# TODO: send an email to member saying his account has been modified
flash('Modifications effectuées', 'ok')
flash('Erreur lors de la modification', 'error')
if addtrophy_form.validate_on_submit():
trophy = Trophy.query.get(
if trophy is not None:
flash('Trophée ajouté', 'ok')
flash("Erreur lors de l'ajout du trophée", 'error')
if deltrophy_form.validate_on_submit():
trophy = Trophy.query.get(
if trophy is not None:
flash('Trophée retiré', 'ok')
flash("Erreur lors du retrait du trophée", 'error')
return render('admin/edit_account.html', user=user, form=form,
addtrophy_form=addtrophy_form, deltrophy_form=deltrophy_form)
@app.route('/admin/account/<user_id>/delete', methods=['GET', 'POST'])
@priv_required('access-admin-panel', 'delete-account')
def adm_delete_account(user_id):
user = Member.query.filter_by(id=user_id).first_or_404()
# Note: A user deleting their own account will be disconnected.
# TODO: Add an overview of what will be deleted.
# * How many posts will be turned into guest posts
# * Option: purely delete the posts in question
# * How many PMs will be deleted (can't unassign PMs)
# * etc.
del_form = AdminDeleteAccountForm()
if del_form.validate_on_submit():
flash('Compte supprimé', 'ok')
return redirect(url_for('adm'))
flash('Erreur lors de la suppression du compte', 'error') = False # Force to tick to delete the account
return render('admin/delete_account.html', user=user, del_form=del_form)