<% response.buffer = true IF request.servervariables("HTTPS") = "off" THEN response.end END IF %> <% bytecount = Request.TotalBytes bytes = Request.BinaryRead(bytecount) IF bytecount <> 0 THEN Set stream = Server.CreateObject("ADODB.Stream") stream.Type = 1 'adTypeBinary stream.Open() stream.Write(bytes) stream.Position = 0 stream.Type = 2 'adTypeText stream.Charset = "utf-8" s = stream.ReadText() stream.Close() Set stream = nothing 'Response.write(s) Set oJSON = New aspJSON 'Load JSON string oJSON.loadJSON(s) 'Get single value api_key = oJSON.data("api_key") school_id = oJSON.data("school_id") pupil_id = oJSON.data("pupil_id") nfc_id = oJSON.data("nfc_id") Set oJSON = Nothing END IF StrError = "None" StrAction = "None" IF api_key<>"" THEN 'run login IF api_key<> "" THEN IF (api_key="ndh032k8scs5pIHXSihd9I392hxeihwd0") THEN 'valid request ELSE StrError="Authentication failed" END IF ELSE StrError = "Authentication data is required" END IF 'school id IF school_id<>"" AND IsNumeric(school_id) THEN 'ok ELSE StrError = "Invalid school data" END IF 'pupil id IF pupil_id <> "" AND IsNumeric(pupil_id) THEN 'ok ELSE StrError = "Invalid pupil data" END IF 'nfc card code IF nfc_id <> "" AND len(nfc_id) < 200 THEN 'ok ELSE StrError = "Invalid nfc data" END IF IF StrError <> "None" THEN 'print the errors Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", "Authentication error" 'Create value End With Response.Write oJSON.JSONoutput() ELSE 'update pupils nfc card dbCBK.Execute("UPDATE cbk_pupils SET `rfID`='"&nfc_id&"' WHERE `schoolID`='"&school_id&"' AND `pupilID`='"&pupil_id&"' limit 1") 'success print api response Set oJSON = New aspJSON With oJSON.data .Add "status", "0" 'Create value End With Response.Write oJSON.JSONoutput() END IF ELSE 'no credentials print failure response StrError="Missing Credentials" Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", ""&StrError&"" 'Create value End With Response.Write oJSON.JSONoutput() END IF %>