5 print "Content-type: text/json"
11 form = cgi.FieldStorage ()
14 if not (form.has_key("username") and form.has_key("pin")):
15 result = {"result" : "Missing information!"}
17 expr_name = re.compile ("^\w*$")
18 expr_pin = re.compile ("^\d{4}$")
19 username = form["username"].value
20 pin = form["pin"].value
21 if (not expr_name.match (form["username"].value)) or (not expr_pin.match (form["pin"].value)):
22 result = {"result" : "Incorrect login!"}
24 output = commands.getoutput ("sudo checkpin " + username + " " + pin)
26 result = {"result" : "Authentication failed!"}
28 if not output == "True":
29 result = {"result" : "PIN not set up."}
31 output = commands.getoutput ("dispense -u " + username + " opendoor");
32 expr_bal = re.compile ("(?P<bal>\d*\.\d*)")
33 balance = expr_bal.search (output).groups()[0]
35 return {"result" : "success", "balance" : balance}
39 print str(checkdata ())