'MAIN activity
Sub Process_Globals
Dim AppID = "xxxxxxxx" As String
Dim RESTid = "xxxxxxxx" As String
Dim parseServerLink = "https://parseapi.back4app.com/" As String
'...
End Sub
'...
Sub checkCompanyIdInternal
Log("checkCompanyIdInternal")
dbC = SQL1.ExecQuery("SELECT * FROM 'company' WHERE id = '1'")
dbC.Position=0
If dbC.GetString("parse_objectID") <> "" Then
company_id = dbC.GetString("id")
company_name = dbC.GetString("name")
parse_objectID = dbC.GetString("parse_objectID")
sessionToken = dbC.GetString("session_token")
If sessionToken = "" Then
lblCompanyName.Text = company_name&" (Odjavljeni ste)"
Else
lblCompanyName.Text = company_name
End If
Else
Log("idi na Register")
StartActivity(actRegister)
Activity.Finish
End If
dbC.Close
End Sub
Sub logout
Dim curl As HttpJob
curl.Initialize("", Me)
curl.PostString(parseServerLink&"logout","")
curl.GetRequest.SetHeader("X-Parse-Application-Id",AppID)
curl.GetRequest.SetHeader("X-Parse-REST-API-Key",RESTid)
curl.GetRequest.SetHeader("X-Parse-Session-Token",sessionToken)
SQL1.ExecNonQuery2("UPDATE company SET session_token=? WHERE id= ?",Array As String("", 1))
curl.Release
Activity.Finish
ExitApplication
End Sub
'REGISTER activity
Sub btnswRegister_Click
kbrd.HideKeyboard
Dim j As HttpJob
j.Initialize("log-in", Me)
Dim user As Map
user.Initialize
user.Put("username", fldRegEmail.Text)
user.Put("password", fldRegPassword.Text)
user.Put("email", fldRegEmail.Text)
user.Put("company_name", fldRegCompany.Text)
user.Put("name", fldRegName.Text)
user.Put("last_name", fldRegLastName.Text)
user.Put("oib", fldRegOIB.Text)
Dim gen As JSONGenerator
gen.Initialize(user)
j.PostString(Main.parseServerLink&"users", gen.ToString)
j.GetRequest.SetHeader("X-Parse-Application-Id", Main.AppID)
j.GetRequest.SetHeader("X-Parse-REST-API-Key", Main.RESTid)
j.GetRequest.SetHeader("X-Parse-Revocable-Session", "1")
j.GetRequest.SetContentType("application/json")
j.Release
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
Log(job.GetString)
Dim parser As JSONParser
parser.Initialize(job.GetString)
Dim root As Map = parser.NextObject
Dim objectId As String = root.Get("objectId")
Dim sessionToken As String = root.Get("sessionToken")
If fldRegOIB.Text = "" Then fldRegOIB.Text = "0"
Main.SQL1.ExecNonQuery2("UPDATE company SET parse_objectID=?, session_token=?, name=?, oib=?, email=?, username=?",Array As String(objectId, sessionToken, fldRegCompany.Text, fldRegOIB.Text, fldRegEmail.Text, fldRegEmail.Text))
StartActivity(Main)
Activity.Finish
Else
Log(job.ErrorMessage)
lblError.Text = job.ErrorMessage
dialogAlert.ShowCustom(pnlErr, "OK", "", "")
End If
job.Release
End Sub
'SIGN IN activity
Sub btnswSignIn_Click
Dim j As HttpJob
j.Initialize("log-in", Me)
j.Download(Main.parseServerLink&"login?username="&fldRegEmail.Text&"&password="&fldRegPassword.Text&"")
j.GetRequest.SetHeader("accept","application/json")
j.GetRequest.SetHeader("X-Parse-Application-Id", Main.AppID)
j.GetRequest.SetHeader("X-Parse-REST-API-Key", Main.RESTid)
j.GetRequest.SetHeader("X-Parse-Revocable-Session", "1")
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
Log(job.GetString)
Dim parser As JSONParser
parser.Initialize(job.GetString)
Dim root As Map = parser.NextObject
Dim objectId As String = root.Get("objectId")
Dim sessionToken As String = root.Get("sessionToken")
Log(objectId &" -- "&sessionToken)
Main.SQL1.ExecNonQuery2("UPDATE company SET session_token=? WHERE id= ?",Array As String(sessionToken, 1))
StartActivity(Main)
Activity.Finish
Else
Log(job.ErrorMessage)
End If
job.Release
End Sub