<% response.buffer = true IF request.servervariables("HTTPS") = "off" THEN response.end END IF Function getSKLNM(sID) IF sID <> "" AND IsNumeric(sID) THEN SET rsSNME=dbCBK.Execute("SELECT schoolname from cbk_schools WHERE schoolID='"&sID&"' limit 1") IF rsSNME.EOF THEN getSKLNM="" Exit Function END IF DO WHILE NOT rsSNME.EOF sk_ret=rsSNME("schoolname") rsSNME.MoveNext loop rsSNME.close SET rsSNME= Nothing getSKLNM=sk_ret ELSE 'missing data getSKLNM="" END IF End Function %> <% 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 userPASS = oJSON.data("password") userNAME = oJSON.data("username") Set oJSON = Nothing END IF StrError = "None" StrAction = "None" IF userNAME<>"" THEN 'run login IF userPASS <> "" THEN IF len(userPASS) < 3 OR len(userPASS) > 30 THEN StrError = "Your password is outside the allowed length" ELSE dcpass=CustEncryptAndEncode(userPASS) END IF ELSE StrError = "Your password is required" END IF 'username is email address IF userNAME <> "" THEN 'ok IF len(userNAME) < 5 OR len(userNAME) > 200 THEN StrError = "Your email address appears invalid" END IF ELSE StrError = "Your email address is required" END IF IF StrError <> "None" THEN 'print the errors Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", "Missing credentials" 'Create value End With Response.Write oJSON.JSONoutput() ELSE 'run login SET rsTL = dbCBK.Execute("SELECT `schoolID`,`cust_token` FROM cbk_school_users WHERE `email`='"&userNAME&"' AND `acpwd`='"&dcpass&"' limit 1") IF rsTL.EOF THEN StrError = "No account found" END IF DO WHILE NOT rsTL.EOF str_school_id=CInt(rsTL("schoolID")) str_school_name=getSKLNM(str_school_id) exiToken=rsTL("cust_token") rsTL.MoveNext loop rsTL.Close SET rsTL = Nothing IF str_school_id<>"" AND IsNumeric(str_school_id) THEN 'login success print api response Set oJSON = New aspJSON With oJSON.data .Add "status", "0" 'Create value .Add "message", "Login Successfull" 'Create value .Add "full_name", ""&str_school_name&"" 'Create value .Add "school_id", ""&str_school_id&"" 'Create value End With Response.Write oJSON.JSONoutput() ELSE ' print login failure response Set oJSON = New aspJSON With oJSON.data .Add "status", "1" 'Create value .Add "message", "No account found" 'Create value End With Response.Write oJSON.JSONoutput() END IF 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 %>