#!/usr/local/bin/python3.3 import cgi import cgitb import pymysql import datetime from functions import get_cookies, phead, ptail cgitb.enable() """ The following issues need to be addressed: -need to add approve user and remove user functions """ cookie = get_cookies() if cookie: print(cookie) fname = cookie["fname"].value lname = cookie["lname"].value name = " ".join((fname, lname)) admin = cookie["admin"].value uid = cookie["uid"].value uname = cookie["uname"].value form = cgi.FieldStorage() email = form.getvalue("email") fname = form.getvalue("fname") lname = form.getvalue("lname") uname = form.getvalue("uname") sid = form.getvalue('sid') qsname = "select uid, email, firstname, lastname, username from User;" data = [] #data should be in the order: user, passwd, host, db with open('./dbinfo.txt') as f: for line in f: line = line.strip('\n') data.append(line) info = [] for item in data: item = item.split(':') info.append(item) user=info[0][1] passwd=info[1][1] host=info[2][1] db=info[3][1] if email == None: email = "" if fname == None: fname = "" if lname == None: lname = "" if uname == None: uname = "" def showUser(email, fname, lname, uname): connection = pymysql.connect(host=host, user=user, db=db, passwd=passwd) cursor = connection.cursor() query1 = """select uid, email, firstname, lastname, username from User;""" cursor.execute(query1) connection.commit() qgeteid = """select uid, email, firstname, lastname, username from User;""" geteid = runQuery(qgeteid, user, passwd) eid = geteid[0][0] connection.commit() cursor.close() connection.close() def runQuery(query, user, passwd): connection = pymysql.connect(host=host,db=db,user=user,passwd=passwd) cursor = connection.cursor() cursor.execute(query) res = cursor.fetchall() cursor.close() connection.close() return res print("Content-type: text/html\n") phead(name, admin) print("""
""") if admin == "1": print('
  • admin

  • ') q1 = """select uid, email, firstname, lastname, username from User;""" if admin == "1" and sid == None: print('

    All Users ADMIN = 1 SID = NONE

    ') q1 = """select uid, email, firstname, lastname, username from User;""" ''' elif admin == "1" and sid: sname = runQuery(qsname, user, passwd)[0][0] print('

    All Users ADMIN = 0, SID%s:

    ' % sname) q1 = """select """ q2 = """""" elif admin == "0" and sid == None: print('

    All Users ADMIN=0, SID=NONE

    ') q1 = """""" q2 = """""" else: sname = runQuery(qsname, user, passwd)[0][0] print('

    All experiments in study %s:

    ' % sname) q1 = """""" q2 = """""" ''' res1 = runQuery(q1, user, passwd) if len(res1) != 0 : print("""
    """ ) n1 = len(res1) for i in range(n1): print('') print("""""" % (str(res1[i][0]),str(res1[i][1]),str(res1[i][2]),str(res1[i][3]),str(res1[i][4]))) print("") print("
    uid Email First Name Last Name Username
    %s%s%s%s%s


    ") ptail() else: print("Location: login.py") print("Content-type: text/html\n")