Share My Creation [B4J] [MySQL] [API] Server (Key + Token) and [B4X] User Login Apps

Updates:
Latest B4XPages user login client apps (using B4J server):
https://www.b4x.com/android/forum/threads/project-template-user-login-client-b4x.161914/

1609578113098.png


Finally I would like to share my B4J API server written in B4J.
Compare to my previous PHP API, this API server implements user access token to authorize user to consume the API.

SQL.zip - SQL script to create necessary database and tables in MySQL server.
jAPI.zip - Source code for server app (B4J).
B4A.zip - Source code for client app using default template (B4A)
B4X.zip - Source code for client app using B4XPages template (B4A, B4i and B4J)

Live server: https://api.puterise.com:17179

12 Jan 2021: Attached B4J client sample. This is a beta version. Some bugs and features will be fixed in the future.
13 Jan 2021: Attached B4X client sample. This is a beta version. Some bugs and features will be fixed in the future. B4J.zip removed.
 

Attachments

  • SQL.zip
    705 bytes · Views: 1,450
  • jAPI.zip
    459.8 KB · Views: 1,559
  • B4A.zip
    51.2 KB · Views: 1,515
  • B4X.zip
    406.5 KB · Views: 1,453
Last edited:

aeric

Expert
Licensed User
Longtime User
Maybe you can check this post by @Mashiane
 

cklester

Well-Known Member
Licensed User
Sorry I am not sure about session. When we use API, we are not using session. We are sending a token as authentication.

What do you mean by a token? In the headers? That's similar to what I'm talking about. A POST with headers or data.

Currently, I can POST traffic to the server (and back) in JSON format. In that JSON, I will put the session_id, which, I guess, I should be putting in a header instead.

Back to the drawing board.
 

cklester

Well-Known Member
Licensed User
Maybe you can check this post by @Mashiane

Is that relevant to a desktop/mobile app that doesn't use cookies to store session variables?
 

aeric

Expert
Licensed User
Longtime User
Is that relevant to a desktop/mobile app that doesn't use cookies to store session variables?
There are difference between web apps which use session (store in server) and cookies (store in client browser) versus mobile apps which is using API to communicate (stateless) with server. In my sample, I am only using 2 fields, API key and Token, so I think keyvaluestore is much simpler than SQLite.
 

cklester

Well-Known Member
Licensed User
There are difference between web apps which use session (store in server) and cookies (store in client browser) versus mobile apps which is using API to communicate (stateless) with server. In my sample, I am only using 2 fields, API key and Token, so I think keyvaluestore is much simpler than SQLite.

So, using your API, we could send up the API key (which would identify the user), and the Byte() I want to store in the MySQL database. Is that correct?
 

aeric

Expert
Licensed User
Longtime User
So, using your API, we could send up the API key (which would identify the user), and the Byte() I want to store in the MySQL database. Is that correct?
My app will get the API key when user login using email and password. This API key acts like a cookie inside the app. Then it will proceed to get the token. The token will expired which is like a session. You can post any data together with the token so it will identified by the token.
To make it more simpler, we can use Base64Encode to convert the file then post as JSON string. When you want to read the data, you can reverse it by using Base64Decode.
 

aeric

Expert
Licensed User
Longtime User
B4X client attached in post #1. The B4X.zip contains all 3 platforms using B4XPages. Take note that there are some bugs I haven't fix. If anyone is kind to help me to fix them, I am very welcome and appreciate. Cheers.
 

Elric

Well-Known Member
Licensed User
Edit: I've red later about bugs. So take the following as notes, please!

Hi aeric,

I'd like to test you work but, in B4X.zip, for B4J:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    #If B4i
    Dim hud As HUD
    #End If
    #If B4J
    Private fx As JFX
    Private clx As clXToastMessage1
    #End If
    Private xui As XUI 'ignore
    Private KVS As KeyValueStore
    Dim strMode As String
    Private txtUserEmail As B4XFloatTextField
    Private txtOldPassword As B4XFloatTextField
    Private txtUserPassword1 As B4XFloatTextField
    Private txtUserPassword2 As B4XFloatTextField  
End Sub

This declaration "Private clx As clXToastMessage1" hasn't a class or library.

And for B4A, error message "relinker-1.3.1.aar" not found:
1610915963822.png


Thank you!
 

sfsameer

Well-Known Member
Licensed User
Longtime User
Edit: I've red later about bugs. So take the following as notes, please!

Hi aeric,

I'd like to test you work but, in B4X.zip, for B4J:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    #If B4i
    Dim hud As HUD
    #End If
    #If B4J
    Private fx As JFX
    Private clx As clXToastMessage1
    #End If
    Private xui As XUI 'ignore
    Private KVS As KeyValueStore
    Dim strMode As String
    Private txtUserEmail As B4XFloatTextField
    Private txtOldPassword As B4XFloatTextField
    Private txtUserPassword1 As B4XFloatTextField
    Private txtUserPassword2 As B4XFloatTextField
End Sub

This declaration "Private clx As clXToastMessage1" hasn't a class or library.

And for B4A, error message "relinker-1.3.1.aar" not found:
View attachment 106428

Thank you!
Download the relinker-1.3.1.aar
from :

"unzip it and copy the files to the additional libraries folder" by erel

original post : https://www.b4x.com/android/forum/threads/b4x-b4xgifview-cross-platform-animated-gif-view.118550/
 

aeric

Expert
Licensed User
Longtime User
Edit: I've red later about bugs. So take the following as notes, please!

Hi aeric,

I'd like to test you work but, in B4X.zip, for B4J:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    #If B4i
    Dim hud As HUD
    #End If
    #If B4J
    Private fx As JFX
    Private clx As clXToastMessage1
    #End If
    Private xui As XUI 'ignore
    Private KVS As KeyValueStore
    Dim strMode As String
    Private txtUserEmail As B4XFloatTextField
    Private txtOldPassword As B4XFloatTextField
    Private txtUserPassword1 As B4XFloatTextField
    Private txtUserPassword2 As B4XFloatTextField
End Sub

This declaration "Private clx As clXToastMessage1" hasn't a class or library.

And for B4A, error message "relinker-1.3.1.aar" not found:
View attachment 106428

Thank you!
Hi Elric,
I use [B4X] B4XGifView - Cross platform animated gif view to load animated image in Splash screen
For B4J: [B4X] [XUI] ToastMessage class to show toast message in B4J

Edit: See post #32 for clXToastMessage1
 
Last edited:

Elric

Well-Known Member
Licensed User
Thank you sfsameer.

For B4J: [B4X] [XUI] ToastMessage class to show toast message in B4J
Thank you aeric.

Just to make it clear for me: it is a class module not a library. I've just added and renamed it from "clXToastMessage" in "clXToastMessage1" (as per declaration).

I've got an error:
B4X:
Compiling code.    Error
Error compiling program.
Error description: Unknown member: show
Error occurred on line: 749
clx.Show(Message, LongDuration)
Word: show
Just no sub "Show" is in clXToastMessage1; only the sub ShowMessage but without arguments.
 

aeric

Expert
Licensed User
Longtime User
Thank you sfsameer.


Thank you aeric.

Just to make it clear for me: it is a class module not a library. I've just added and renamed it from "clXToastMessage" in "clXToastMessage1" (as per declaration).

I've got an error:
B4X:
Compiling code.    Error
Error compiling program.
Error description: Unknown member: show
Error occurred on line: 749
clx.Show(Message, LongDuration)
Word: show
Just no sub "Show" is in clXToastMessage1; only the sub ShowMessage but without arguments.
Sorry, this is the correct thread.
[B4X] [XUI] ToastMessage Class Modifications
 

Puthut Wibowo

Member
Licensed User
this examples of applications that are very useful ...

Can I get tutorial how to install into the hosting, I'm using the php version here

Thank you in advance
 

aeric

Expert
Licensed User
Longtime User
I tried to add emoticon to the varchar field and getting error.
[user/update][Exception] (SQLException) java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\x9C' for column 'user_name' at row 1


The solution is to use utf8mb4 collation for MySQL database.

The problem is with the SET NAMES utf8 command. In MySQL the utf8 character set is not truly utf8, it supports characters up 3 bytes only and the character in question has 4 bytes
https://stackoverflow.com/questions/39095860/how-to-connect-to-mysql-using-utf8-within-a-perl-script

1611863425068.png
 

Puthut Wibowo

Member
Licensed User
Hi Aeric,

I've create a Threat :

Thanks


Please start a new thread with your question e.g. "How to host my PHP web application in shared hosting?"
 

pixet

Member
Licensed User
Longtime User
I tried to fill in as indicated, but I can't activate the registered user.
Any suggestions ?
 
Top