Commit 9fcc8a6e authored by Sli's avatar Sli

Add ban list

parent 1167c4ca
No preview for this file type
......@@ -4,7 +4,9 @@ import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Debug;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -30,6 +32,7 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
private EditText _ipAddress;
private EditText _portNumber;
private ArrayList<Key_List> key_list;
private ArrayList<String> ban_list;
@Override
......@@ -46,6 +49,8 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
validateIPAddress.setOnClickListener(this);
key_list = new ArrayList<Key_List>();
ban_list = new ArrayList<String>();
}
@Override
......@@ -88,8 +93,45 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
e.printStackTrace();
}
//Send key_list to next activity
//Intent intent = new Intent(Login.this, Read_QR_Code.class);
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
display(getString(R.string.serverError), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
display(getString(R.string.serverError), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
display(getString(R.string.serverError), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
});
client.get(server + "/banlist", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
try {
for (int index = 0; index < response.length(); index++){
ban_list.add(response.getString(index));
}
} catch (JSONException e){
e.printStackTrace();
}
//Send banlist to next activity
Intent intent = new Intent(Login.this, Read_QR_Code.class);
intent.putParcelableArrayListExtra("key_list", key_list);
intent.putStringArrayListExtra("ban_list", ban_list);
intent.putExtra("server", server);
startActivity(intent);
}
......@@ -114,7 +156,6 @@ public class Login extends ActionBarActivity implements View.OnClickListener {
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
});
}
}
......
......@@ -40,6 +40,7 @@ public class Read_QR_Code extends ActionBarActivity implements View.OnClickListe
private static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
private ArrayList<Key_List> key_list = null;
private ArrayList<String> ban_list = null;
private String server;
private EditText _nbrPlace;
private EditText _barCode;
......@@ -52,6 +53,7 @@ public class Read_QR_Code extends ActionBarActivity implements View.OnClickListe
Intent intent = getIntent();
if (intent != null) {
key_list = intent.getParcelableArrayListExtra("key_list");
ban_list = intent.getStringArrayListExtra("ban_list");
server = intent.getStringExtra("server");
}
......@@ -152,6 +154,11 @@ public class Read_QR_Code extends ActionBarActivity implements View.OnClickListe
return;
}
if (ban_list != null && ban_list.contains(result)){
display("Ce ticket est banni !", false);
return;
}
Iterator<Key_List> itr = key_list.iterator();
while (itr.hasNext()) {
Key_List key = itr.next();
......
This diff is collapsed.
keys.json
banlist.json
sqliteDB.db
......@@ -3,7 +3,7 @@
# @Author: Bartuccio Antoine (Sli) (klmp200)
# @Date: 2016-07-03 17:57:28
# @Last Modified by: klmp200
# @Last Modified time: 2016-11-10 00:43:04
# @Last Modified time: 2016-11-14 02:29:45
from bottle import Bottle, static_file, request, template, redirect
from bottle.ext import sqlite
......@@ -32,6 +32,18 @@ def find_product(keys, id_product):
return obj
return None
def get_banlist():
with open('../data/banlist.json', 'r') as json_data:
return json.load(json_data)
def is_banned(code):
if code in get_banlist():
return True
else:
return False
app = Bottle()
plugin = sqlite.Plugin(dbfile='../data/sqliteDB.db')
app.install(plugin)
......@@ -67,6 +79,14 @@ def GetKeys():
return static_file("keys.json", root="../data/")
@app.route('/banlist')
def GetBanlist():
"""
Return json file for banned tickets
"""
return static_file("banlist.json", root="../data/")
@app.route('/delete/<db_id>')
def DeleteTicket(db, db_id=None):
"""
......@@ -95,7 +115,8 @@ def DisplayAdmin(db):
"""
form = ObtainGetArgs(request.query, ['id', 'verifKey'])
tickets = SearchDb(db, form)
return template('admin.simple', table=tickets, form=form)
return template('admin.simple', table=tickets, form=form,
banlist=get_banlist())
@app.route('/admin/ajax', method='GET')
......@@ -114,7 +135,7 @@ def ScanTicketView(status=None):
"""
A web app to check tickets
"""
response = ObtainGetArgs(request.query, ['av', 'valid', 'child'])
response = ObtainGetArgs(request.query, ['av', 'valid', 'child', 'banned'])
return template('scan.simple', response=response)
......@@ -126,6 +147,7 @@ def CheckTicketPost(db):
code = request.forms.get('code').upper()
code_list = code.split()
is_child = False
banned = is_banned(code)
if len(code_list) >= 4:
verif_key = code_list.pop(-1)
place_tot = SafeInt(code_list.pop(-1))
......@@ -135,8 +157,7 @@ def CheckTicketPost(db):
verif_key = ""
product = {}
if CheckHmac(code, product, verif_key) and place_tot > 0:
print("HMAC")
if not banned and CheckHmac(code, product, verif_key) and place_tot > 0:
used_qt = SafeInt(request.forms.get('qt'))
is_child = product['is_child']
......@@ -148,10 +169,12 @@ def CheckTicketPost(db):
status = {'available': 0, 'valid': False}
if request.forms.get('ajax') == "True":
return dict({'av': status['available'], 'valid': status['valid'], 'child': is_child})
return dict({'av': status['available'], 'valid': status['valid'],
'child': is_child, 'banned': banned})
else:
redirect('/webscan?av={}&valid={}&child={}'.format(status['available'],
status['valid'], is_child))
redirect('/webscan?av={}&valid={}&child={}&banned={}'.format(status['available'],
status['valid'],
is_child, banned))
def CheckHmac(code, product, verif_key):
......
......@@ -20,6 +20,23 @@
<input type="text" name="verifKey" value="{{form['verifKey']}}"/>
<button type="submit" class="pure-button pure-button-primary">Rechercher</button>
</form>
% if len(banlist) > 0:
<h2>Tickets bannis</h2>
<table class="pure-table pure-table-bordered">
<thead>
<tr>
<th>Code</th>
</tr>
</thead>
<tbody>
% for code in banlist:
<tr>
<td>{{code}}</td>
</tr>
% end
</tbody>
</table>
% end
<h2>Données</h2>
<table class="pure-table pure-table-bordered">
<thead>
......
......@@ -21,6 +21,8 @@
<p class="alert alert-warning" style="font-size: 30px">Ceci est une place pour mineur !</p><br>
% end
<p class="alert alert-success">Billet valide : {{response['av']}} places restantes</p>
% elif response['banned'] and response['banned'] == "True":
<p class="alert alert-error">BILLET BANNI !</p>
% else:
<p class="alert alert-error">Billet invalide ou déjà utilisé</p>
% end
......@@ -73,6 +75,8 @@
if (data['child']){
$("#response").prepend('<p class="alert alert-warning" style="font-size: 30px">Ceci est une place pour mineur !</p><br>');
}
} else if (data['banned']) {
$("#response").prepend('<p class="alert alert-error">BILLET BANNI !</p>');
} else {
$("#response").prepend('<p class="alert alert-error">Billet invalide ou déjà utilisé</p>');
}
......
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