def login(): if request.method == 'POST': args = request.form db = myutils.mydb() userid = args['userid'].lower() if not db.checkuserexists(userid): return render_template('login.html', errmsg='User does not exist') elif db.checkpassword(userid, args['password']): retstring = redirect('/vote') resp = make_response(retstring) resp.set_cookie('user', args['userid'], 3600) return resp else: return render_template('login.html', errmsg='Incorrect password') return 'Unsupported request type GET'
def votepage(): if request.cookies.has_key('user'): db = myutils.mydb() userid = request.cookies['user'].lower() cname = db.getChinese(userid) candidate_restaurants = db.getRestaurants() voted_user_dict = {} for uid, rest in user_voted_dict.items(): if voted_user_dict.has_key(rest): if uid not in voted_user_dict[rest]: voted_user_dict[rest] += ',' + db.getChinese(uid) else: voted_user_dict[rest] = db.getChinese(uid) return render_template('vote.html', name=cname, restaurants=candidate_restaurants, votes=voted_user_dict) else: return redirect('/')
def sync_vote(): db = myutils.mydb() db.sync_vote(user_voted_dict) print "synchronized votes to db at " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if request.method == 'POST': args = request.form db = myutils.mydb() userid = args['userid'].lower() if not db.checkuserexists(userid): return render_template('login.html', errmsg='User does not exist') elif db.checkpassword(userid, args['password']): retstring = redirect('/vote') resp = make_response(retstring) resp.set_cookie('user', args['userid'], 3600) return resp else: return render_template('login.html', errmsg='Incorrect password') return 'Unsupported request type GET' @app.route('/logout') def logout(): resp = make_response(redirect('/')) resp.delete_cookie('user') return resp if __name__ == '__main__': db = myutils.mydb() for uid, rest in db.getAllVotesToday(): vote(uid, rest) sync_thread = threading.Thread(target=thread_func) sync_thread.start() app.run('0.0.0.0')