Added cookies
parent
fdbd4d2f09
commit
661e87715a
21
main.py
21
main.py
|
@ -1,7 +1,8 @@
|
|||
from bottle import template, get, run, post, request, redirect
|
||||
from bottle import template, get, run, post, request, redirect, response
|
||||
from chess import Game
|
||||
|
||||
|
||||
KEY = "abcdefgh"
|
||||
TEMPLATE = "template.html"
|
||||
games = dict()
|
||||
|
||||
|
@ -10,17 +11,23 @@ def is_submitted(name):
|
|||
|
||||
@get("/")
|
||||
def index():
|
||||
if request.get_cookie("gameid", secret=KEY) not in games.keys():
|
||||
game = Game()
|
||||
id = max(list(games.keys())+[0]) + 1
|
||||
id = str(max(list(map(int, games.keys()))+[0]) + 1)
|
||||
games[id] = game
|
||||
redirect("/game/{}/".format(id))
|
||||
response.set_cookie("gameid", id, path='/', secret=KEY)
|
||||
redirect("/game/")
|
||||
|
||||
@get("/game/<id:int>/")
|
||||
def show(id):
|
||||
@get("/game/")
|
||||
def show():
|
||||
id = request.get_cookie("gameid", secret=KEY)
|
||||
if id not in games:
|
||||
redirect("/")
|
||||
return template(TEMPLATE, game=games[id], valid=True)
|
||||
|
||||
@post("/game/<id:int>/")
|
||||
def move(id):
|
||||
@post("/game/")
|
||||
def move():
|
||||
id = request.get_cookie("gameid", secret=KEY)
|
||||
valid = True
|
||||
if is_submitted("newgame"):
|
||||
redirect("/")
|
||||
|
|
Loading…
Reference in New Issue