Suppression des sessions

This commit is contained in:
guimoz 2017-01-27 10:49:01 +01:00
parent 7ae284b48c
commit 81e2714d00

View file

@ -1,6 +1,6 @@
# -*- coding: utf8 -*
from flask import Flask, request, session, g, redirect, url_for, \
from flask import Flask, request, g, redirect, url_for, \
abort, render_template, flash
from functools import wraps
@ -187,23 +187,11 @@ def playable_required(f):
ip=get_ip()
user = get_player_from_ip(ip)
if 'ip' in session:
# On enregistre l'ip afin d'éviter les problèmes lors du déplacement des user (rez <-> Supelec)
session['ip'] = ip
# Attention : un utilisateur inscrit ne peut pas être forcé à être
# désinscrit s'il n'enlève pas son cookie de session. On évite la
# réexécution de la requête.
if 'subscribed' not in session or not session['subscribed'] or session['ip'] != ip:
session['subscribed'] = user is not None
session['ip'] = ip
if DEBUG:
print('New user : ',session)
if not session['subscribed']:
if not user:
return render_template('not_subscribed.html')
# Un utilisateur banni ne peut pas jouer
if user and is_banned(user['id']):
elif is_banned(user['id']):
return banned()
return f(*args, **kwargs)
@ -335,8 +323,7 @@ def banned_ip():
@app.route('/')
@playable_required
def home():
ip = get_ip()
player = get_player_from_ip(ip)
player = get_player_from_ip(get_ip())
#if ip not in ['10.69.8.5', '10.69.8.202']:
# abort(403)
@ -344,9 +331,6 @@ def home():
if DEBUG:
print(player, 'arrived')
if session.get('logged_in'):
pass
bans = sorted(get_bans(player['id']), \
key=lambda ban: ban['time'], \
reverse=True)
@ -409,25 +393,5 @@ def play():
return render_template('play.html', players=players)
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('home'))
return render_template('login.html', error=error)
@app.route('/logout')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('home'))
if __name__ == '__main__':
app.run()