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.

account.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from flask import redirect, url_for, request, flash
  2. from flask_login import login_required, current_user, logout_user
  3. from app import app, db
  4. from app.forms.account import UpdateAccountForm, RegistrationForm, DeleteAccountForm
  5. from app.models.users import Member
  6. from app.utils.render import render
  7. @app.route('/account', methods=['GET', 'POST'])
  8. @login_required
  9. def edit_account():
  10. form = UpdateAccountForm()
  11. if form.submit.data:
  12. if form.validate_on_submit():
  13. if form.avatar.data:
  14. f = form.avatar.data
  15. f.save("./app/static/" + current_user.avatar)
  16. current_user.update(
  17. email=form.email.data or None,
  18. password=form.password.data or None,
  19. birthday=form.birthday.data,
  20. signature=form.signature.data,
  21. bio=form.biography.data,
  22. newsletter=form.newsletter.data
  23. )
  24. db.session.merge(current_user)
  25. db.session.commit()
  26. current_user.update_trophies("on-profile-update")
  27. flash('Modifications effectuées', 'ok')
  28. else:
  29. flash('Erreur lors de la modification', 'error')
  30. return render('account.html', form=form)
  31. @app.route('/account/delete', methods=['GET', 'POST'])
  32. @login_required
  33. def delete_account():
  34. del_form = DeleteAccountForm()
  35. if del_form.submit.data:
  36. if del_form.validate_on_submit():
  37. db.session.delete(current_user)
  38. logout_user()
  39. db.session.commit()
  40. flash('Compte supprimé', 'ok')
  41. return redirect(url_for('index'))
  42. else:
  43. flash('Erreur lors de la suppression du compte', 'error')
  44. del_form.delete.data = False # Force to tick to delete the account
  45. return render('delete_account.html', del_form=del_form)
  46. @app.route('/register', methods=['GET', 'POST'])
  47. def register():
  48. if current_user.is_authenticated:
  49. return redirect(url_for('index'))
  50. form = RegistrationForm()
  51. if form.validate_on_submit():
  52. member = Member(form.username.data, form.email.data, form.password.data)
  53. db.session.add(member)
  54. db.session.commit()
  55. flash('Inscription réussie', 'ok')
  56. return redirect(url_for('validation'))
  57. return render('register.html', title='Register', form=form)
  58. @app.route('/register/validation/')
  59. def validation():
  60. if current_user.is_authenticated:
  61. return redirect(url_for('index'))
  62. return render('validation.html')