Commit 079e684c authored by Sli's avatar Sli

Vérification serveur side complète, la documentation arrive bientôt

parent fafb5750
#!/bin/sh
cd data
sqlite3 sqliteDB.db < db.sql
CREATE Table ticket (
id INTEGER PRIMARY KEY AUTOINCREMENT,
verifKey TEXT UNIQUE NOT NULL,
avaliablePlaces INTEGER NOT NULL
);
......@@ -3,20 +3,73 @@
# @Author: klmp200
# @Date: 2016-07-03 17:57:28
# @Last Modified by: klmp200
# @Last Modified time: 2016-07-03 22:32:39
# @Last Modified time: 2016-07-04 17:50:18
from bottle import route, static_file, run, request, template
from bottle import Bottle, static_file, request
from bottle.ext import sqlite
app = Bottle()
plugin = sqlite.Plugin(dbfile='../data/sqliteDB.db')
app.install(plugin)
@route('/keys')
@app.route('/keys')
def GetKeys():
return static_file("keys.json", root="../data/")
@route('/validate', method='POST')
def Validate():
data = request.json
@app.route('/validate', method='POST')
def Validate(db):
try:
send = request.json
ticket = db.execute('SELECT * from ticket where verifKey=:key',
{"key": send['verif']}).fetchone()
if (ticket is None):
message = NewEntry(db, send)
else:
message = UpdateEntry(db, send, ticket)
except:
message = '<p>Error processing data</p>'
return message
def NewEntry(db, data):
avaliable = data['nb'] - data['qt']
response = {
"avaliable": avaliable,
"valid": True
}
db.execute('INSERT into ticket(verifKey, avaliablePlaces) values (?, ?)',
(data['verif'], avaliable))
return dict(response)
def UpdateEntry(db, data, obj):
avaliableP = obj['avaliablePlaces'] - data['qt']
if avaliableP >= 0:
avaliable = True
else:
avaliableP = obj['avaliablePlaces']
avaliable = False
response = {
"avaliable": avaliableP,
"valid": avaliable
}
db.execute('UPDATE ticket SET avaliablePlaces=:av WHERE id=:id',
{"av": avaliableP, "id": obj['id']})
return dict(response)
return template('<p>id: {{id}}, type: {{type}}</p>', id=data['id'], type=data['type'])
app.run(host='localhost', port=8080, debug=True)
run(host='localhost', port=8080, debug=True)
app.uninstall(plugin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment