Sub Class_Globals
Private ResponseTOclient As ServletResponse
End Sub
Public Sub Initialize
End Sub
Sub Handle(req As ServletRequest, resp As ServletResponse)
ResponseTOclient = resp
Dim data_map As Map = req.GetMultipartData(Null, 100)
For Each key As String In data_map.Keys
Select key
Case "username"
Dim p As Part = data_map.Get("username")
Dim username As String = p.GetValue("utf8")
Case "password"
Dim p As Part = data_map.Get("password")
Dim password As String = p.GetValue("utf8")
End Select
Next
checkexisting(username, password)
startmessageloop
End Sub
Sub checkexisting(username As String, password As String)
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("check_existing_user", Array(email))
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For(req) req_Result(Res As DBResult)
Dim row() As Object = Res.Rows.Get(0)
Dim count As Int = row(0)
If count > 0 Then
ResponseTOclient.Write("Email already registered") 'In situations where this is the first response, I get an empty string
stopmessageloop
Else
RegisterUser(username, password)
End If
End If
j.Release
End Sub
Sub RegisterUser(username As String, password As String)
Dim cmd As DBCommand = CreateCommand("register_user", Array(username, password))
Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
ResponseTOclient.Write("User successfully registered")
stopmessageloop
End If
j.Release
End Sub