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.
 
 
 
 
 

79 lines
2.9 KiB

from flask import render_template, flash, redirect, url_for, request
from flask_login import login_user, logout_user, current_user, login_required
from werkzeug.urls import url_parse
from app import app, db
from app.forms import LoginForm, RegistrationForm, UpdateAccountForm
from app.models.users import Member
@app.route('/')
def index():
login_form = LoginForm()
return render_template('index.html', login_form=login_form)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return redirect(url_for('index'))
login_form = LoginForm()
if form.validate_on_submit():
member = Member.query.filter_by(username=form.username.data).first()
if member is None or not member.check_password(form.password.data):
flash('Pseudo ou mot de passe invalide', 'error')
return redirect(request.referrer)
login_user(member, remember=form.remember_me.data)
flash('Connexion réussie', 'info')
return redirect(request.referrer)
@app.route('/logout')
def logout():
logout_user()
flash('Déconnexion réussie', 'info')
return redirect(url_for('index'))
@app.route('/account', methods=['GET', 'POST'])
def account():
if not current_user.is_authenticated:
flash('Veuillez vous authentifier', 'warning')
return redirect(url_for('index'))
login_form = LoginForm()
form2 = UpdateAccountForm()
if request.method == "POST":
if form2.validate_on_submit():
current_user.update(
email = form2.email.data,
password = form2.password.data,
signature = form2.signature.data,
biography = form2.biography.data,
birthday = form2.birthday.data,
receive_newsletter = form2.newsletter.data)
db.session.add(current_user)
db.session.commit()
flash('Modifications effectuées', 'ok')
else:
flash('Erreur lors de la modification', 'error')
return render_template('account.html', login_form=login_form, form2=form2)
@app.route('/register', methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('index'))
login_form = LoginForm()
form2 = RegistrationForm()
if form2.validate_on_submit():
member = Member(form2.username.data, form2.email.data, form2.password.data)
member.biography = ""
member.signature = ""
db.session.add(member)
db.session.commit()
flash('Inscription réussie', 'ok')
return redirect(url_for('validation'))
return render_template('register.html', title='Register', login_form=login_form, form2=form2)
@app.route('/register/validation/')
def validation():
if current_user.is_authenticated :
return redirect(url_for('index'))
login_form = LoginForm()
return render_template('validation.html', login_form=login_form)