diff --git a/app/database.py b/app/database.py index 32c6155..50c5ec1 100644 --- a/app/database.py +++ b/app/database.py @@ -100,7 +100,7 @@ def add_user(u): def update_user(u): #query_db("UPDATE users SET (NAME, LONGNAME, EMAIL, RFID_ID, ISBLACK, ISBARON, ISSHOWN) VALUES (?, ?, ?, ?, ?, ?, ?) WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) - query_db("UPDATE users SET NAME=?, LONGNAME=?, EMAIL=?, RFID_ID=?, ISBLACK=?, ISBARON=?, ISSHOWN=? WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) + query_db("UPDATE users SET NAME=?, PASSWORD=?, LONGNAME=?, EMAIL=?, RFID_ID=?, ISBLACK=?, ISBARON=?, ISSHOWN=? WHERE ID=?", (u.name, u.password, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) get_db().commit() diff --git a/app/gui.py b/app/gui.py index 177f4e1..e45cc79 100644 --- a/app/gui.py +++ b/app/gui.py @@ -59,9 +59,7 @@ class MainWindow(wx.Frame): with app.app_context(): for i in range(0, int(self.panelUser.GetAmount())): add_consume(self.user.name, get_product_by_name(drink).id) - plot_total(self.user) - plot_total() - plot_list(4) + plot_all_thread(self.user) self.switchPanels() def switchPanels(self): diff --git a/app/plot.py b/app/plot.py index 204e88d..01cb242 100644 --- a/app/plot.py +++ b/app/plot.py @@ -3,9 +3,24 @@ from matplotlib.dates import WeekdayLocator, DayLocator, HourLocator, DateFormat import numpy as np from user import User from database import * +import thread as th + +def plot_all_thread(user = None): + #if user != None: + # th.start_new_thread(plot_all, (user,)) + #else: + # th.start_new_thread(plot_all, ()) +#def plot_all(user = None): +# + if user != None: + plot_total(user) + plot_total() + plot_list(4) + print 'plot_all' def plot_total(user = None): + print 'plot_total' today = datetime.date.today() delta = datetime.timedelta(days=1) begin = datetime.date.today() - datetime.timedelta(weeks=2) @@ -97,20 +112,27 @@ def plot_list(duration): for consumption in consumed: allconsumptions[consumption.prodnr-1][consumption.consumer-1] += 1 - #print 'debug ------------------' - #print consumptions - #print '------------------------' + #cumulate consumptions for cumulative bar graph + i = 0 + for consumptions in allconsumptions: + if i > 0: + j = 0 + for consumption in consumptions: + allconsumptions[i][j] += allconsumptions[i-1][j] + j += 1 + i += 1 plt.xkcd() fig, ax = plt.subplots() - colors = ['red','green','blue'] + colors = ['blue', 'green', 'red', 'yellow', 'orange' , 'black'] - i=0 - for consumptions in allconsumptions: - ax.barh(np.arange(len(consumptions)), consumptions, label=get_product_by_id(i+1).name, align='center', height=(0.5), color=colors[i]) - i+=1 + #plot reversed to print longest bar lowest + i = len(allconsumptions) + for consumptions in reversed(allconsumptions): + ax.barh(np.arange(len(consumptions)), consumptions, label=get_product_by_id(i).name, align='center', height=(0.5), color=colors[i-1]) + i -= 1 names = list() @@ -126,7 +148,7 @@ def plot_list(duration): ax.yaxis.set_ticks_position('none') ax.xaxis.set_ticks_position('none') - plt.subplots_adjust(left=0.2) + plt.subplots_adjust(left=0.15) #plt.tick_params(which='minor', length=4) #plt.tick_params(which='major', length=5) @@ -144,4 +166,4 @@ def plot_list(duration): plt.savefig('app/static/bierliste.png', dpi=100) #800x600 fig.set_size_inches(15, 10) - plt.savefig('app/static/bierliste_small.png', dpi=72) + plt.savefig('app/static/bierliste_small.png', dpi=72) \ No newline at end of file diff --git a/app/views.py b/app/views.py index f0fe22f..4383da2 100644 --- a/app/views.py +++ b/app/views.py @@ -6,7 +6,7 @@ from plot import * from user import User from product import Product from consumption import Consumption - +import bcrypt @app.route('/static/') @@ -41,7 +41,9 @@ def login(): if u is None: error = 'User does not exist!' return render_template('login.html', error=error, user=get_user_by_name(session.get('name'))) - if u.password != request.form['password']: + #if u.password != request.form['password']: + # bcrypt.checkpy(plaintxt, hash) + if not bcrypt.checkpw(request.form['password'], u.password): error = 'Wrong password!' return render_template('login.html', error=error, user=get_user_by_name(session.get('name'))) @@ -76,10 +78,11 @@ def manage_users_add(): error = "Username not unique!" if request.form['password1'] == request.form['password2']: - u.password = request.form['password1'] + #u.password = request.form['password1'] + u.password = bcrypt.hashpw(request.form['password1'], bcrypt.gensalt()) else: - error="Passwords do not match!" - u.longname=request.form['longname'] + error = "Passwords do not match!" + u.longname = request.form['longname'] u.email = request.form['email'] u.rfid_id = request.form['rfid_id'] @@ -211,9 +214,7 @@ def consume(): username = session.get('name') add_consume(username, prod.id) message = "Du hast gerade ein %s konsumiert." % prod.name - plot_total(get_user_by_name(session.get('name'))) - plot_total() - plot_list(4) + plot_all_thread(get_user_by_name(session.get('name'))) return render_template('consume.html', products=products, message=message, user=get_user_by_name(session.get('name'))) @app.route('/personal') @@ -224,5 +225,14 @@ def personal(): @app.route('/billing') @requires_baron def billing(): - return render_template('billing.html', user=get_user_by_name(session.get('name'))) + +#migrate the db to hashed passwords +#@app.route('/hashdb') +#@requires_baron +#def hashdb(): +# users = get_users() +# for user in users: +# user.password = bcrypt.hashpw(user.password, bcrypt.gensalt()) +# update_user(user) +# return render_template('index.html', users=users, user=get_user_by_name(session.get('name'))) diff --git a/test/database.db b/test/database.db index 70394e2..f1b97b2 100644 Binary files a/test/database.db and b/test/database.db differ