public Sub BANano_Ready()
Dim rows As List = MiniCSS.AddRows("r", 3, "row")
MiniCSS.AddColumns("c",rows.get(0),2, "col-sm-6")
MiniCSS.AddColumns("c",rows.get(1),1, "col-sm-12")
MiniCSS.AddColumns("c",rows.get(2),1, "col-sm-12")
MiniCSS.BuildGrid("body", rows)
' show a login or logoff button, depends if we have the Cookie
Dim Token As String = BANano.GetCookie("BANanoDemoCookie")
If Token = "" Then
MiniCSS.Button("r1c1", "login", "Login", "primary", Me, False)
Else
MiniCSS.Button("r1c1", "login", "Log off", "primary", Me, False)
End If
MiniCSS.LoginForm("r1c1", "loginForm", Me)
' button to test our REST Api
MiniCSS.Button("r2c1", "info", "Get Info", "", Me, False)
End Sub
public Sub Login_Clicked(event As BANanoEvent)
Dim Token As String = BANano.GetCookie("BANanoDemoCookie")
If Token = "" Then
If BANano.CheckInternetConnectionWait Then
' open the popup
BANano.GetElement("#loginform").SetChecked(True)
Else
' no use to try to login
MiniCSS.Content("r3c1", "contajax", "You are not connected to the internet!")
End If
Else
BANano.RemoveCookie("BANanoDemoCookie", "")
' set to a log on button
MiniCSS.Button("r1c1", "login", "Login", "primary", Me, True)
MiniCSS.Content("r3c1", "contajax", "You are now logged off from the server!")
End If
End Sub
public Sub Info_Clicked(event As BANanoEvent)
If BANano.CheckInternetConnectionWait Then
Dim Token As String = BANano.GetCookie("BANanoDemoCookie")
If Token = "" Then
' we will have to login
MiniCSS.Content("r3c1", "contajax", "You are not logged in on the server!")
Return
End If
' we are logged in, so lets get some REST api running
Dim headers As Map
headers.Initialize
headers.put("Content-Type", "application/json")
headers.Put("Authorization", $"BANBearer ${Token}"$)
Dim res As String = BANano.CallAjaxWait("http://localhost:51042/getinfo","POST","json", "", False, headers)
MiniCSS.Content("r3c1", "contajax", res)
Else
MiniCSS.Content("r3c1", "contajax", "You are not connected to the internet!")
End If
End Sub
public Sub LoginformBtnLogin_Clicked(event As BANanoEvent)
' get the username and password
Dim User As String = BANano.GetElement("#loginformusername").GetValue
Dim Password As String = BANano.GetElement("#loginformpassword").GetValue
' close the popup
BANano.GetElement("#loginform").SetChecked(False)
' try to logon to our server
Dim headers As Map
headers.Initialize
headers.put("Content-Type", "application/json")
headers.Put("Authorization", "BANBasic " & BANano.ToBase64(User & ":" & Password))
Dim res As String = BANano.CallAjaxWait("http://localhost:51042/","POST","json", $""$, False, headers)
Dim json As BANanoJSONParser
json.Initialize(res)
Dim m As Map = json.NextObject
Dim CheckStatus As Int = m.GetDefault("BANanoStatus",0)
Select Case CheckStatus
Case 801 ' login is ok
MiniCSS.Content("r3c1", "contajax", "You are logged in on the server!")
Dim expires As Int = m.GetDefault("BANExpires", 0)
BANano.SetCookie("BANanoDemoCookie", m.GetDefault("BANToken", ""), $"{"expires": ${expires}}"$)
' set to a logoff button
MiniCSS.Button("r1c1", "login", "Log off", "primary", Me, True)
Case Else ' login is not ok
MiniCSS.Content("r3c1", "contajax", "You are not logged in on the server (wrong password?)!")
End Select
End Sub