#!/usr/bin/env python # for common gateway interface functionality: import cgi # user custom library: import lunchlib # required by cgi: print "Content-Type: text/html" print # this script must be supplied with a username: arguments = cgi.FieldStorage() if "uname" not in arguments: lunchlib.write_fail("Username not received in POST.") else: uname = arguments["uname"].value # javascript to validate input and go forward to report generation: lunchlib.write_js(''' function goToDetailedReport(form) { // check to see if the start month is written correctly: if (/^\d{4}-\d{2}$/.test(form.start_month.value)) { // if the format is correct, split up the string: bits = form.start_month.value.split('-'); // use the parts to construct a new date object to compare to // the current date. Note that the constructor assumes that // January is the 0th month, so subtract 1. // Also give the "day" paramater a value of the 1st
print "</table>" return True ######## main processing starts here: # needed for cgi print "Content-Type: text/html" print # this script requires at least a username and start month: arguments = cgi.FieldStorage() if "uname" not in arguments or "start_month" not in arguments: lunchlib.write_fail("Some data not received in POST.") else: uname = arguments["uname"].value start_month = arguments["start_month"].value # grab the end month if it has been supplied, # otherwise default to the same as the start month: if "end_month" not in arguments: end_month = start_month else: end_month = arguments["end_month"].value # write javascript for going back to main menu: lunchlib.write_js( """ function goToMainMenu(form) {
# for common gateway interface access: import cgi # custom user library: import lunchlib # necessary for cgi: print "Content-Type: text/html" print # this script must be passed a username, lunch date, and lunch amount: arguments = cgi.FieldStorage() if "uname" not in arguments or "ldate" not in arguments \ or "amount" not in arguments: lunchlib.write_fail("Some data not received in POST.") else: uname = arguments["uname"].value ldate = arguments["ldate"].value amount = arguments["amount"].value # html that will eventually be written to the page: status_message = "" try: # connect to the database: db = pg.DB(dbname=lunchlib.dbname, host=lunchlib.dbhost, user=lunchlib.dbuser, passwd=lunchlib.dbpasswd)
# for common gateway interface functionality import cgi # custom user library import lunchlib # content type must always be specified for cgi: print "Content-Type: text/html" print # this script must be passed a username, password, first and last name: arguments = cgi.FieldStorage() if "uname" not in arguments or "passwd" not in arguments \ or "fname" not in arguments or "lname" not in arguments: lunchlib.write_fail("Some data was not received by POST") else: uname = arguments["uname"].value plainpw = arguments["passwd"].value fname = arguments["fname"].value lname = arguments["lname"].value try: # connect to the database: db = pg.DB(dbname=lunchlib.dbname, host=lunchlib.dbhost, user=lunchlib.dbuser, passwd=lunchlib.dbpasswd) # check if username already exists rows = db.query(''' select 1 from employee
import pg # for common gateway interface functionality import cgi # custom user library import lunchlib # content type must always be specified for cgi: print "Content-Type: text/html" print # this script must be passed a username and password: arguments = cgi.FieldStorage() if "uname" not in arguments or "passwd" not in arguments: lunchlib.write_fail("Username and password not received by POST.") else: uname = arguments["uname"].value passwd = arguments["passwd"].value try: # connect to the database: db = pg.DB(dbname=lunchlib.dbname, host=lunchlib.dbhost, user=lunchlib.dbuser, passwd=lunchlib.dbpasswd) # check if the user exists and if so, retrieve her password: rows = db.query(''' select passwd from employee where uname='{0}' '''.format(uname)).getresult()
import pg # for common gateway interface functionality import cgi # custom user library import lunchlib # content type must always be specified for cgi: print "Content-Type: text/html" print # this script must be passed a username and password: arguments = cgi.FieldStorage() if "uname" not in arguments or "passwd" not in arguments: lunchlib.write_fail("Username and password not received by POST.") else: uname = arguments["uname"].value passwd = arguments["passwd"].value try: # connect to the database: db = pg.DB(dbname=lunchlib.dbname, host=lunchlib.dbhost, user=lunchlib.dbuser, passwd=lunchlib.dbpasswd) # check if the user exists and if so, retrieve her password: rows = db.query(''' select passwd from employee