5 print "Content-type: text/json"
12 form = cgi.FieldStorage ()
13 cookies = Cookie.SimpleCookie(os.environ.get("HTTP_COOKIE",""))
16 if not (cookies.has_key("username") and cookies.has_key("pin")):
17 result = {"result" : "Missing information!"}
19 expr_name = re.compile ("^\w*$")
20 expr_pin = re.compile ("^\d{4}$")
21 username = cookies["username"].value.lower ()
22 pin = cookies["pin"].value
23 if (not expr_name.match (cookies["username"].value)) or (not expr_pin.match (cookies["pin"].value)):
24 result = {"result" : "Incorrect login!"}
26 output = commands.getoutput ("sudo checkpin " + username + " " + pin)
28 result = {"result" : "Authentication failed!"}
30 if not output == "True":
31 result = {"result" : "PIN not set up."}
33 output = commands.getoutput ("dispense acct " + username);
34 expr_bal = re.compile ("(?P<bal>\d*\.\d*)")
35 balance = expr_bal.search (output).groups()[0]
37 return {"result" : "success", "balance" : balance}
40 print str(checkdata ())