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.

routes.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from flask import render_template, flash, redirect, url_for, request
  2. from flask_login import login_user, logout_user, current_user, login_required
  3. from werkzeug.urls import url_parse
  4. from app import app, db
  5. from app.forms import LoginForm, RegistrationForm
  6. from app.models import User
  7. @app.route('/', methods=['GET', 'POST'])
  8. def index():
  9. form = LoginForm()
  10. if form.validate_on_submit():
  11. user = User.query.filter_by(username=form.username.data).first()
  12. if user is None or not user.check_password(form.password.data):
  13. flash('pseudo ou mot de passe invalide')
  14. return redirect(url_for('index'))
  15. login_user(user, remember=form.remember_me.data)
  16. return render_template('index.html', form=form)
  17. @app.route('/logout/')
  18. def logout():
  19. logout_user()
  20. return redirect(url_for('index'))
  21. @app.route('/register', methods=['GET', 'POST'])
  22. def register():
  23. if current_user.is_authenticated:
  24. return redirect(url_for('index'))
  25. form = LoginForm()
  26. form2 = RegistrationForm()
  27. if form2.validate_on_submit():
  28. user = User(username=form2.username.data, email=form2.email.data)
  29. user.set_password(form2.password.data)
  30. db.session.add(user)
  31. db.session.commit()
  32. flash('Congratulations, you are now a registered user!')
  33. return redirect(url_for('validation'))
  34. return render_template('register.html', title='Register', form=form, form2 = form2)
  35. @app.route('/register/validation/')
  36. def validation():
  37. if current_user.is_authenticated :
  38. return redirect(url_for('index'))
  39. form = LoginForm()
  40. return render_template('validation.html', form = form)