示例#1
0
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'
示例#2
0
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('/')
示例#3
0
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")
示例#4
0
    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')